List of usage examples for java.lang.reflect InvocationTargetException getTargetException
public Throwable getTargetException()
From source file:de.andrena.tools.macker.plugin.CommandLineFile.java
public static void main(String[] args) throws Exception { if (args.length == 0 || args.length > 2) { System.err.println("Usage: CommandLineFile <main class> [command line arguments file]"); System.exit(1);// www . j av a2 s. c om } String className = args[0]; Class<?> clazz = Class.forName(className); Method main = clazz.getMethod("main", new Class[] { String[].class }); List<String> lines = new ArrayList<String>(); if (args.length == 2) { Reader in = new InputStreamReader(new FileInputStream(args[1]), "UTF-8"); try { lines = IOUtils.readLines(in); } finally { in.close(); } } try { main.invoke(null, new Object[] { lines.toArray(new String[lines.size()]) }); } catch (InvocationTargetException ex) { Throwable cause = ex.getTargetException(); if (cause instanceof Error) { throw (Error) cause; } throw (Exception) cause; } }
From source file:ClassLoaderDemo0.java
public static void main(String[] argv) { System.out.println("ClassLoaderDemo starting"); ClassLoaderDemo0 loader = new ClassLoaderDemo0(); Class c = null;//from ww w. ja v a 2 s . com Object demo; try { /* Load the "Demo" class from memory */ System.out.println("About to load class Demo"); c = loader.loadClass("Demo", true); System.out.println("About to instantiate class Demo"); demo = c.newInstance(); System.out.println("Got Demo class loaded: " + demo); /* Now try to call a method */ Method mi = c.getMethod("test", null); mi.invoke(demo, null); } catch (InvocationTargetException e) { // The invoked method threw an exception. We get it // wrapped up inside another exception, hence the // extra call here: e.getTargetException().printStackTrace(); System.out.println("Could not run test method"); } catch (Exception e) { e.printStackTrace(); System.out.println("Could not run test method"); } }
From source file:Main.java
/** TargetException handler */ private static void handleTargetException(InvocationTargetException ex) throws IOException { Throwable t = ex.getTargetException(); if (t instanceof IOException) { throw (IOException) t; } else if (t instanceof RuntimeException) { throw (RuntimeException) t; } else if (t instanceof Error) { throw (Error) t; }//w w w .j a v a2s . c o m }
From source file:Main.java
public static void invokeInEDTAndWait(Runnable runnable) throws Exception { if (SwingUtilities.isEventDispatchThread()) { runnable.run();/* w w w.java 2 s. c om*/ } else { try { SwingUtilities.invokeAndWait(runnable); } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof Exception) throw (Exception) targetException; if (targetException instanceof Error) throw (Error) targetException; throw new IllegalStateException(targetException); } catch (InterruptedException e) { throw new IllegalStateException(e); } } }
From source file:Main.java
public static void recreate(Activity activity) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { recreateHC(activity);//from ww w . j a v a 2s. c o m } else { try { recreateGB(activity); } catch (InvocationTargetException e) { e.getTargetException().printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.manager.DeleteObjectByOID.java
@Atomic public static Boolean run(String externalId) throws FenixServiceException { check(RolePredicates.MANAGER_PREDICATE); try {/* w w w . j a va 2s. c om*/ MethodUtils.invokeMethod(FenixFramework.getDomainObject(externalId), "delete", null); } catch (InvocationTargetException e) { if (e.getTargetException() != null) { if (e.getTargetException() instanceof WriteOnReadError) { throw ((WriteOnReadError) e.getTargetException()); } throw new FenixServiceException(e.getTargetException()); } throw new FenixServiceException(e); } catch (NoSuchMethodException e) { throw new FenixServiceException(e); } catch (IllegalAccessException e) { throw new FenixServiceException(e); } return true; }
From source file:Main.java
/** * Causes runnable to have its run method called in the dispatch thread of * the event queue. This will happen after all pending events are processed. * The call blocks until this has happened. *///www . j av a 2s . c om public static void invokeAndWait(final Runnable runnable) { if (EventQueue.isDispatchThread()) { runnable.run(); } else { try { EventQueue.invokeAndWait(runnable); } catch (InterruptedException exception) { // Someone don't want to let us sleep. Go back to work. } catch (InvocationTargetException target) { final Throwable exception = target.getTargetException(); if (exception instanceof RuntimeException) { throw (RuntimeException) exception; } if (exception instanceof Error) { throw (Error) exception; } // Should not happen, since {@link Runnable#run} do not allow checked exception. throw new UndeclaredThrowableException(exception, exception.getLocalizedMessage()); } } }
From source file:cf.spring.servicebroker.AccessorUtils.java
/** * Invokes the method of the specified object with some method arguments. *///from ww w.ja va 2s. com public static Object invokeMethod(Object object, Method method, Object... args) throws Throwable { try { return method.invoke(object, args); } catch (InvocationTargetException e) { throw e.getTargetException(); } }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.manager.TransferDomainObjectProperty.java
@Atomic public static void run(DomainObject srcObject, DomainObject dstObject, String slotName) throws FenixServiceException { check(RolePredicates.MANAGER_PREDICATE); try {//ww w . ja va 2 s . c o m Object srcProperty = PropertyUtils.getSimpleProperty(srcObject, slotName); if (srcProperty != null && srcProperty instanceof Collection) { Collection srcCollection = (Collection) srcProperty; Object dstProperty = PropertyUtils.getSimpleProperty(dstObject, slotName); if (dstProperty instanceof Collection) { Collection dstCollection = (Collection) dstProperty; dstCollection.addAll(srcCollection); } } else { PropertyUtils.setSimpleProperty(dstObject, slotName, srcProperty); } } catch (InvocationTargetException e) { if (e.getTargetException() != null) { if (e.getTargetException() instanceof WriteOnReadError) { throw ((WriteOnReadError) e.getTargetException()); } throw new FenixServiceException(e.getTargetException()); } throw new FenixServiceException(e); } catch (IllegalAccessException e) { throw new FenixServiceException(e); } catch (NoSuchMethodException e) { throw new FenixServiceException(e); } }
From source file:com.espertech.esper.epl.script.mvel.MVELHelper.java
private static ExprValidationException handleTargetException(String scriptName, InvocationTargetException ex) { Throwable mvelException = ex.getTargetException(); String message = "Exception compiling MVEL script '" + scriptName + "': " + mvelException.getMessage(); log.info(message, mvelException);/*from www .j a v a 2 s . c o m*/ return new ExprValidationException(message, mvelException); }