List of usage examples for java.lang Throwable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:ai.general.net.MethodHandler.java
/** * Handles the request by calling the method represented by this handler. * Request parameters are converted to match the method signature if possible. If no conversion * is possible, the method is not called. * * @param request The request to handle. *//*from w w w. ja va2 s . c o m*/ public void handle(Request request) { log.entry(request.getUri().toString()); try { Object[] raw_args = request.getArguments().toArray(); if (raw_args.length != parameter_types_.length) { request.getResult() .addError(new Result.Error("invalid number of method arguments", "got " + raw_args.length + " arguments for method with " + parameter_types_.length + " arguments")); log.exit("invalid number of arguments"); return; } Object[] args = new Object[raw_args.length]; for (int i = 0; i < raw_args.length; i++) { args[i] = json_parser_.convertValue(raw_args[i], parameter_types_[i]); } Object result = method_.invoke(instance_, args); if (result != null) { request.getResult().addValue(result); } } catch (InvocationTargetException e) { log.catching(Level.TRACE, e); Throwable cause = e.getCause(); if (cause != null) { if (cause instanceof RpcException) { request.getResult() .addError(new Result.Error(cause.getMessage(), ((RpcException) cause).getDetails())); } else { request.getResult().addError(new Result.Error(cause.getClass().getName(), cause.getMessage())); } } else { request.getResult().addError(new Result.Error("unspecified exception thrown by RPC method", null)); } } catch (ReflectiveOperationException e) { log.catching(Level.TRACE, e); request.getResult().addError(new Result.Error("cannot call method with specified arguments", null)); } catch (Exception e) { log.catching(Level.TRACE, e); request.getResult().addError(new Result.Error(e.getClass().getName(), e.getMessage())); } log.exit(); }
From source file:net.sf.ehcache.constructs.web.filter.Filter.java
/** * Checks whether a throwable, its root cause if it is a {@link ServletException}, or its cause, if it is a * Chained Exception matches an entry in the exceptionsToLogDifferently list * * @param throwable/*ww w . ja v a 2 s . co m*/ * @return true if the class name of any of the throwables is found in the exceptions to log differently */ private boolean matches(Throwable throwable) { if (exceptionsToLogDifferently == null) { return false; } if (exceptionsToLogDifferently.indexOf(throwable.getClass().getName()) != -1) { return true; } if (throwable instanceof ServletException) { Throwable rootCause = (((ServletException) throwable).getRootCause()); if (exceptionsToLogDifferently.indexOf(rootCause.getClass().getName()) != -1) { return true; } } if (throwable.getCause() != null) { Throwable cause = throwable.getCause(); if (exceptionsToLogDifferently.indexOf(cause.getClass().getName()) != -1) { return true; } } return false; }
From source file:org.malaguna.cmdit.bbeans.AbstractBean.java
/** * It runs a command safely and catching all error info. If commands fail, * it will show error info standard way. * //ww w . j a v a 2 s. c o m * @param cmd * @return */ @Override protected Command runCommand(Command cmd) { cmd.setLocale(getLocale()); cmd.setUser(getAuthUserFromSession()); try { cmd = super.runCommand(cmd); if ((cmd != null) && (cmd.getUserComment() != null)) { setInfoMessage("Command Info:", cmd.getUserComment()); } } catch (Exception e) { Throwable ce = (e.getCause() != null) ? e.getCause() : e; String aux = getMessage(ce.getClass().getName(), getLocale()); String errMsg = null; if (aux != null) errMsg = String.format("%s: %s", aux, ce.getLocalizedMessage()); else errMsg = ce.getLocalizedMessage(); setErrorMessage("Command Error:", errMsg); cmd = null; } return cmd; }
From source file:com.graphhopper.http.GraphHopperServletIT.java
@Test public void testGraphHopperWebRealExceptions() { GHResponse rsp;/*from w w w . ja va 2 s . co m*/ Throwable ex; GraphHopperAPI hopper = new GraphHopperWeb(); assertTrue(hopper.load(getTestAPIUrl())); // IllegalStateException (Wrong Request) rsp = hopper.route(new GHRequest()); assertFalse("Errors expected but not found.", rsp.getErrors().isEmpty()); ex = rsp.getErrors().get(0); assertTrue("Wrong Exception found: " + ex.getClass().getName() + ", IllegalStateException expected.", ex instanceof IllegalStateException); // IllegalArgumentException (Wrong Points) rsp = hopper.route(new GHRequest(0.0, 0.0, 0.0, 0.0)); assertFalse("Errors expected but not found.", rsp.getErrors().isEmpty()); ex = rsp.getErrors().get(0); assertTrue("Wrong Exception found: " + ex.getClass().getName() + ", IllegalArgumentException expected.", ex instanceof IllegalArgumentException); // IllegalArgumentException (Vehicle not supported) rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setVehicle("SPACE-SHUTTLE")); assertFalse("Errors expected but not found.", rsp.getErrors().isEmpty()); ex = rsp.getErrors().get(0); assertTrue("Wrong Exception found: " + ex.getClass().getName() + ", IllegalArgumentException expected.", ex instanceof IllegalArgumentException); // UnsupportedOperationException // RuntimeException // Exception }
From source file:com.alliander.osgp.acceptancetests.firmwaremanagement.UpdateFirmwareSteps.java
@DomainStep("the update firmware request is received") public void whenTheUpdateFirmwareRequestIsReceived() throws Exception { LOGGER.info("[When the update firmware request is received]"); try {//from ww w . ja v a2s.c o m this.updateFirmwareAsyncResponse = this.firmwareManagementEndpoint.updateFirmware(ORGANISATION_ID, this.request); } catch (final Throwable t) { LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage()); this.throwable = t; } }
From source file:com.alliander.osgp.acceptancetests.firmwaremanagement.UpdateFirmwareSteps.java
@DomainStep("the update firmware response request is received") public void whenTheUpdateFirmwareResponseRequestIsReceived() { LOGGER.info("WHEN: \"the update firmware response request is received\"."); try {// w w w. j a v a2 s . c om this.response = this.firmwareManagementEndpoint.getUpdateFirmwareResponse(ORGANISATION_ID, this.updateFirmwareAsyncRequest); } catch (final Throwable t) { LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage()); this.throwable = t; } }
From source file:com.sinosoft.one.mvc.web.impl.module.ErrorHandlerDispatcher.java
public ErrorHandlerDispatcher(ControllerErrorHandler errorHandler) { this.errorHandler = errorHandler; Method[] methods = this.errorHandler.getClass().getMethods(); for (final Method method : methods) { if (Modifier.isAbstract(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) { continue; }// w ww . j a v a 2 s . c o m if (method.getName().equals("onError")) { final Class<?>[] parameterClasses = method.getParameterTypes(); if (parameterClasses.length == 2 && parameterClasses[INVOCATION_INDEX] == Invocation.class && Throwable.class.isAssignableFrom(parameterClasses[THROWABLE_INDEX])) { delegates.add(new ErrorHandlerDelegate() { @Override public Method getMethod() { return method; } @Override public Object onError(Invocation inv, Throwable ex) throws Throwable { Object[] args = new Object[] { inv, ex }; try { return method.invoke(ErrorHandlerDispatcher.this.errorHandler, args); } catch (Throwable e) { logger.error("error happened when handling error " + ex.getClass() + " at " + ErrorHandlerDispatcher.this.toString()); throw e; } } }); } } } Collections.sort(delegates, new Comparator<ErrorHandlerDelegate>() { public int compare(ErrorHandlerDelegate o1, ErrorHandlerDelegate o2) { if (o1.getMethod().getParameterTypes()[THROWABLE_INDEX] .isAssignableFrom(o2.getMethod().getParameterTypes()[THROWABLE_INDEX])) { return 1; } else if (o2.getMethod().getParameterTypes()[THROWABLE_INDEX] .isAssignableFrom(o1.getMethod().getParameterTypes()[THROWABLE_INDEX])) { return -1; } else { return o1.getMethod().getParameterTypes()[THROWABLE_INDEX].getName() .compareTo(o2.getMethod().getParameterTypes()[THROWABLE_INDEX].getName()); } } }); }
From source file:com.laxser.blitz.web.impl.module.ErrorHandlerDispatcher.java
public ErrorHandlerDispatcher(ControllerErrorHandler errorHandler) { this.errorHandler = errorHandler; Method[] methods = this.errorHandler.getClass().getMethods(); for (final Method method : methods) { if (Modifier.isAbstract(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) { continue; }/*from w w w .j a va 2 s . c o m*/ if (method.getName().equals("onError")) { final Class<?>[] parameterClasses = method.getParameterTypes(); if (parameterClasses.length == 2 && parameterClasses[INVOCATION_INDEX] == Invocation.class && Throwable.class.isAssignableFrom(parameterClasses[THROWABLE_INDEX])) { delegates.add(new ErrorHandlerDelegate() { @Override public Method getMethod() { return method; } @Override public Object onError(Invocation inv, Throwable ex) throws Throwable { Object[] args = new Object[] { inv, ex }; try { return method.invoke(ErrorHandlerDispatcher.this.errorHandler, args); } catch (Throwable e) { logger.error("error happened when handling error " + ex.getClass() + " at " + ErrorHandlerDispatcher.this.toString()); throw e; } } }); } } } Collections.sort(delegates, new Comparator<ErrorHandlerDelegate>() { @Override public int compare(ErrorHandlerDelegate o1, ErrorHandlerDelegate o2) { if (o1.getMethod().getParameterTypes()[THROWABLE_INDEX] .isAssignableFrom(o2.getMethod().getParameterTypes()[THROWABLE_INDEX])) { return 1; } else if (o2.getMethod().getParameterTypes()[THROWABLE_INDEX] .isAssignableFrom(o1.getMethod().getParameterTypes()[THROWABLE_INDEX])) { return -1; } else { return o1.getMethod().getParameterTypes()[THROWABLE_INDEX].getName() .compareTo(o2.getMethod().getParameterTypes()[THROWABLE_INDEX].getName()); } } }); }
From source file:com.alliander.osgp.acceptancetests.adhocmanagement.ResumeScheduleSteps.java
@DomainStep("the resume schedule request is received") public void whenTheRequestIsReceived() { LOGGER.info("WHEN: \"the request is received\"."); try {// w ww. ja v a 2 s . com this.resumeScheduleAsyncResponse = this.adHocManagementEndpoint .resumeSchedule(this.organisation.getOrganisationIdentification(), this.request); } catch (final Throwable t) { LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage()); this.throwable = t; } }