Code example for InvocationTargetException

Methods: getCause

0
        findClassMethod.setAccessible(true);
        try { 
            return (Class<?>)findClassMethod.invoke(jarLoader, name);
        } 
        catch (InvocationTargetException e) {
           throw (Exception)e.getCause();
        } 
    } 
 
    /** Trying to find a class that we fail to preload should throw a CNFE. */ 
    public final void testFindClass_classNotFound() throws Exception { 
        try { 
            // Will throw ClassNotFoundException 
            _findClass(mFrameworkClassLoader, "not.a.valid.ClassName");  //$NON-NLS-1$
        } catch (ClassNotFoundException e) {
            // check the message in the CNFE 
            assertEquals("not.a.valid.ClassName", e.getMessage());  //$NON-NLS-1$
            return; 
        } 
        // Exception not thrown - this is a failure 
        fail("Expected ClassNotFoundException not thrown");