List of usage examples for java.lang.reflect InvocationTargetException getCause
public Throwable getCause()
From source file:org.tango.server.device.InitImpl.java
private void manageInitError(final StateImpl stateImpl, final StatusImpl statusImpl, final InvocationTargetException e) { try {//from w w w . j a v a 2 s. c o m logger.error(Constants.INIT_FAILED, e.getCause()); stateImpl.stateMachine(DeviceState.FAULT); if (e.getCause() instanceof DevFailed) { logger.error("Tango error at Init: {}", DevFailedUtils.toString((DevFailed) e.getCause())); statusImpl.statusMachine("Init failed: " + DevFailedUtils.toString((DevFailed) e.getCause()), DeviceState.FAULT); } else { final StringWriter sw = new StringWriter(); e.getCause().printStackTrace(new PrintWriter(sw)); final String stacktrace = sw.toString(); statusImpl.statusMachine("Init failed: " + stacktrace, DeviceState.FAULT); } } catch (final DevFailed e1) { logger.error(DevFailedUtils.toString(e1)); } }
From source file:com.googlecode.android_scripting.facade.CameraFacade.java
public Camera openCamera(int cameraId) throws Exception { int sSdkLevel = android.os.Build.VERSION.SDK_INT; Camera result;//w w w . ja va 2s .co m if (sSdkLevel < Build.VERSION_CODES.GINGERBREAD) { result = Camera.open(); } else { Method _open = Camera.class.getMethod("open", int.class); try { result = (Camera) _open.invoke(null, cameraId); } catch (InvocationTargetException e) { Throwable th = e.getCause(); String s = th.getMessage(); Log.e("error: " + s); result = null; } } return result; }
From source file:com.hubspot.utils.circuitbreaker.CircuitBreakerInvocationHandler.java
/** * Called from a Proxy instance to invoke a method on the realObj stored by this handler. * /* www .ja v a2s . c o m*/ * If a "blacklisted" exception is thrown, we inform our CircuitBreakerPolicy let it * tell us whether we should move states. */ @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { getLog().debug("circuit breaker wrapped method invocation = " + method.toGenericString()); Throwable fromInvocation = null; Object ret = null; try { if (blacklist.containsKey(method) && policy.getCurrentState() == CircuitBreakerState.OPEN && !policy.shouldAttemptReset()) { // breaker is open, just throw our standard CircuitBreakerException throw new CircuitBreakerException(); } // circuit breaker is either open or half-open, do our invocation ret = method.invoke(realObj, args); } catch (InvocationTargetException e) { // The underlying method was called successfully, but threw an exception. // we want to pass that exception on. fromInvocation = e.getCause(); } catch (IllegalArgumentException e) { // "In a properly constructed proxy, this should never happen." getLog().debug("Illegal argument exception in circuit breaker handler" + e); throw e; } catch (IllegalAccessException e) { // "In a properly constructed proxy, this should never happen." getLog().debug("Illegal access exception in circuit breaker handler" + e); throw e; } // exception was thrown, determine if it was blacklisted and if we should trip if (fromInvocation != null) { if (blacklist.containsKey(method)) { Class[] blacklistedExceptionTypes = blacklist.get(method); if (ArrayUtils.contains(blacklistedExceptionTypes, fromInvocation.getClass())) { policy.failedBlacklistedCall(method); } } else { policy.successfulCall(method); } throw fromInvocation; } if (blacklist.containsKey(method)) policy.successfulCall(method); return ret; }
From source file:com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolderTest.java
@Test public void testGetAnnotationValuesWrongArg() throws ReflectiveOperationException { SuppressWarningsHolder holder = new SuppressWarningsHolder(); Method getAllAnnotationValues = holder.getClass().getDeclaredMethod("getAnnotationValues", DetailAST.class); getAllAnnotationValues.setAccessible(true); DetailAST methodDef = new DetailAST(); methodDef.setType(TokenTypes.METHOD_DEF); methodDef.setText("Method Def"); methodDef.setLineNo(0);//from w ww.ja va2 s. c om methodDef.setColumnNo(0); try { getAllAnnotationValues.invoke(holder, methodDef); fail("Exception expected"); } catch (InvocationTargetException ex) { assertTrue(ex.getCause() instanceof IllegalArgumentException); assertEquals("Expression or annotation array" + " initializer AST expected: Method Def[0x0]", ex.getCause().getMessage()); } }
From source file:de.ma.it.common.sm.transition.MethodTransition.java
private void invokeMethod(Object[] arguments) { try {/*from w ww .j a v a2 s . c om*/ if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing method " + method + " with arguments " + Arrays.asList(arguments)); } method.invoke(target, arguments); } catch (InvocationTargetException ite) { if (ite.getCause() instanceof RuntimeException) { throw (RuntimeException) ite.getCause(); } throw new MethodInvocationException(method, ite); } catch (IllegalAccessException iae) { throw new MethodInvocationException(method, iae); } }
From source file:org.apache.mina.statemachine.transition.MethodTransition.java
private void invokeMethod(Object[] arguments) { try {//w w w . j a va 2s. c o m if (log.isDebugEnabled()) { log.debug("Executing method " + method + " with arguments " + Arrays.asList(arguments)); } method.invoke(target, arguments); } catch (InvocationTargetException ite) { if (ite.getCause() instanceof RuntimeException) { throw (RuntimeException) ite.getCause(); } throw new MethodInvocationException(method, ite); } catch (IllegalAccessException iae) { throw new MethodInvocationException(method, iae); } }
From source file:org.apache.tuscany.sca.implementation.bpel.ode.provider.BPELInvoker.java
public Message invoke(Message msg) { try {/* www. j av a 2s . c o m*/ if (isCallback) { // Extract the callback endpoint metadata callbackEPR = msg.getFrom(); } // end if Object[] args = msg.getBody(); Object resp = doTheWork(args); msg.setBody(resp); } catch (InvocationTargetException e) { msg.setFaultBody(e.getCause()); } return msg; }
From source file:com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolderTest.java
@Test public void testGetAnnotationTargetWrongArg() throws ReflectiveOperationException { SuppressWarningsHolder holder = new SuppressWarningsHolder(); Method getAnnotationTarget = holder.getClass().getDeclaredMethod("getAnnotationTarget", DetailAST.class); getAnnotationTarget.setAccessible(true); DetailAST methodDef = new DetailAST(); methodDef.setType(TokenTypes.METHOD_DEF); methodDef.setText("Method Def"); DetailAST parent = new DetailAST(); parent.setType(TokenTypes.ASSIGN);/*from w w w . j a v a2 s .com*/ parent.setText("Parent ast"); parent.addChild(methodDef); parent.setLineNo(0); parent.setColumnNo(0); try { getAnnotationTarget.invoke(holder, methodDef); fail("Exception expected"); } catch (InvocationTargetException ex) { assertTrue(ex.getCause() instanceof IllegalArgumentException); assertEquals("Unexpected container AST: Parent ast[0x0]", ex.getCause().getMessage()); } }
From source file:com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolderTest.java
@Test public void testGetAllAnnotationValuesWrongArg() throws ReflectiveOperationException { SuppressWarningsHolder holder = new SuppressWarningsHolder(); Method getAllAnnotationValues = holder.getClass().getDeclaredMethod("getAllAnnotationValues", DetailAST.class); getAllAnnotationValues.setAccessible(true); DetailAST methodDef = new DetailAST(); methodDef.setType(TokenTypes.METHOD_DEF); methodDef.setText("Method Def"); methodDef.setLineNo(0);/*from ww w . j av a 2 s . c om*/ methodDef.setColumnNo(0); DetailAST lparen = new DetailAST(); lparen.setType(TokenTypes.LPAREN); DetailAST parent = new DetailAST(); parent.addChild(lparen); parent.addChild(methodDef); try { getAllAnnotationValues.invoke(holder, parent); fail("Exception expected"); } catch (InvocationTargetException ex) { assertTrue(ex.getCause() instanceof IllegalArgumentException); assertEquals("Unexpected AST: Method Def[0x0]", ex.getCause().getMessage()); } }
From source file:com.linecorp.bot.spring.boot.support.LineMessageHandlerSupport.java
@VisibleForTesting void dispatch(Event event) { try {//from w w w . j ava2 s .c o m dispatchInternal(event); } catch (InvocationTargetException e) { log.trace("InvocationTargetException occurred.", e); log.error(e.getCause().getMessage(), e.getCause()); } catch (Error | Exception e) { log.error(e.getMessage(), e); } }