List of usage examples for java.lang RuntimeException RuntimeException
public RuntimeException(Throwable cause)
From source file:MainClass.java
public static void main(String args[]) { try {/*from ww w . j a v a 2 s . c o m*/ throw new RuntimeException("demo"); } catch (Exception e) { } }
From source file:Main.java
public static void main(String[] args) { Runnable badTask = () -> { throw new RuntimeException("Throwing exception from task execution..."); };/* w w w .jav a 2s.co m*/ ExecutorService exec = Executors.newSingleThreadExecutor(); exec.execute(badTask); exec.shutdown(); }
From source file:Main.java
public static void main(String[] args) { Callable<Object> badTask = () -> { throw new RuntimeException("Throwing exception from task execution..."); };// www.j a va2 s.co m ExecutorService exec = Executors.newSingleThreadExecutor(); Future submittedTask = exec.submit(badTask); try { Object result = submittedTask.get(); } catch (ExecutionException e) { System.out.println(e.getMessage()); System.out.println(e.getCause().getMessage()); } catch (InterruptedException e) { e.printStackTrace(); } exec.shutdown(); }
From source file:CheckVersion.java
public static void main(String[] args) { String version = System.getProperty("java.version"); char minor = version.charAt(2); char point = version.charAt(4); if (minor < '4' || point < '1') throw new RuntimeException("JDK 1.4.1 or higher " + "is required to run the examples in this book."); System.out.println("JDK version " + version + " found"); }
From source file:Main.java
public static void main(String[] args) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(2); scheduledThreadPoolExecutor.scheduleAtFixedRate(() -> { throw new RuntimeException(" scheduleAtFixedRate test ScheduledThreadPoolExecutor"); }, 0, 3000, TimeUnit.MILLISECONDS); scheduledThreadPoolExecutor.scheduleAtFixedRate(() -> { System.out.println("scheduleAtFixedRate: " + LocalDateTime.now().format(formatter)); }, 0, 2000, TimeUnit.MILLISECONDS); scheduledThreadPoolExecutor.schedule(() -> { System.out.println("schedule"); }, 1, TimeUnit.SECONDS);//from w ww . j a v a2s. c om }
From source file:Main.java
public static void main(String[] args) throws Exception { Runnable myRunnable = new Runnable() { @Override/* www.java2 s .c o m*/ public void run() { try { System.out.println("Start: " + Thread.currentThread().getName()); Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } } }; Thread one = new Thread(myRunnable); Thread two = new Thread(myRunnable); one.start(); two.start(); List<Thread> threads = getThreadsFor(myRunnable); for (Thread thread : threads) System.out.println("Found: " + thread.getName()); }
From source file:SpecificMethodInfoDemo.java
public static void main(final String[] args) { final Method byteValueMeth; final Method waitMeth; final Method waitDetailMeth; try {// w ww. j a v a2 s . c o m byteValueMeth = Number.class.getMethod("byteValue", null); waitMeth = Number.class.getMethod("wait", new Class[] {}); waitDetailMeth = Number.class.getMethod("wait", new Class[] { long.class, int.class }); } catch (final NoSuchMethodException ex) { throw new RuntimeException(ex); } System.out.println("byteValueMeth = " + byteValueMeth.toString()); System.out.println("waitMeth = " + waitMeth.toString()); System.out.println("waitDetailMeth = " + waitDetailMeth.toString()); }
From source file:Main.java
static public void main(String args[]) throws Exception { PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras); if (pss.length == 0) throw new RuntimeException("No printer services available."); PrintService ps = pss[0];//w ww . ja va2 s . co m System.out.println("Printing to " + ps); DocPrintJob job = ps.createPrintJob(); FileInputStream fin = new FileInputStream("YOurImageFileName.PNG"); Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null); job.print(doc, pras); fin.close(); }
From source file:PrintImage.java
static public void main(String args[]) throws Exception { PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras); if (pss.length == 0) throw new RuntimeException("No printer services available."); PrintService ps = pss[0];//from w w w. j a v a2s . c o m System.out.println("Printing to " + ps); DocPrintJob job = ps.createPrintJob(); FileInputStream fin = new FileInputStream("YOurImageFileName.PNG"); Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null); job.print(doc, pras); fin.close(); }
From source file:PrintImage.java
static public void main(String args[]) throws Exception { try {//from w w w . ja va 2 s. c om PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras); if (pss.length == 0) throw new RuntimeException("No printer services available."); PrintService ps = pss[0]; System.out.println("Printing to " + ps); DocPrintJob job = ps.createPrintJob(); FileInputStream fin = new FileInputStream("YOurImageFileName.PNG"); Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null); job.print(doc, pras); fin.close(); } catch (IOException ie) { ie.printStackTrace(); } catch (PrintException pe) { pe.printStackTrace(); } }