List of usage examples for java.lang Throwable getCause
public synchronized Throwable getCause()
From source file:com.zimbra.cs.datasource.DataSourceManager.java
private static String generateErrorMessage(Throwable t) { StringBuilder buf = new StringBuilder(); while (t != null) { // HACK: go with JavaMail error message if (t.getClass().getName().startsWith("javax.mail.")) { String msg = t.getMessage(); return msg != null ? msg : t.toString(); }/* w w w.jav a 2 s.c om*/ if (buf.length() > 0) { buf.append(", "); } String msg = t.getMessage(); buf.append(msg != null ? msg : t.toString()); t = t.getCause(); } return buf.toString(); }
From source file:com.intuit.tank.util.ExceptionHandler.java
/** * @param status/*from w w w .j a v a 2s . co m*/ * @return */ private Throwable getRoot(Throwable t) { while (t.getCause() != null && t.getCause() != t) { t = t.getCause(); } return t; }
From source file:dap4.servlet.CDMDSP.java
/** * Make sure that NC4Iosp is registered and library loaded *///from w w w . j ava 2 s .co m static public void loadNc4Iosp() throws DapException { if (nc4loaded) return; nc4loaded = true; if (!NetcdfFile.iospRegistered(NC4CLASS)) { try { // register before H5Iosp NetcdfFile.registerIOProvider(NC4CLASS, false); Nc4Iosp.setLibraryAndPath(null, null); // use defaults } catch (Throwable e) { DapLog.error("Cant load IOSP Nc4Iosp"); throw new DapException(e.getMessage(), e.getCause()); } } }
From source file:com.tesora.dve.mysqlapi.repl.MyReplicationVisitorDispatch.java
public static void executeLDB(ServerDBConnection dbCon, final ChannelHandlerContext channelHandlerContext, final byte[] readData) throws SQLException { try {//w w w . j a va 2 s .c om final SSConnection ssCon1 = dbCon.getSSConn(); Throwable t = ssCon1.executeInContext(new Callable<Throwable>() { public Throwable call() { try { LoadDataBlockExecutor.executeInsert(channelHandlerContext, ssCon1, LoadDataBlockExecutor.processDataBlock(channelHandlerContext, ssCon1, readData)); } catch (Throwable e) { return e; } return null; } }); if (t != null && t.getCause() != null) { throw new PEException(t); } } catch (Throwable t) { throw new SQLException(t); } }
From source file:org.apache.camel.component.dns.DNSIPEndpointSpringTest.java
@Test public void testNullIPRequests() throws Exception { _resultEndpoint.expectedMessageCount(0); try {//from w ww .j a v a 2s. co m _template.sendBodyAndHeader("hello", "dns.domain", null); } catch (Throwable t) { assertTrue(t.getCause() instanceof IllegalArgumentException); } _resultEndpoint.assertIsSatisfied(); }
From source file:org.apache.camel.component.dns.DNSIPEndpointSpringTest.java
@Test public void testEmptyIPRequests() throws Exception { _resultEndpoint.expectedMessageCount(0); try {/*from w w w.j av a 2s . c o m*/ _template.sendBodyAndHeader("hello", "dns.domain", ""); } catch (Throwable t) { assertTrue(t.getCause() instanceof IllegalArgumentException); } _resultEndpoint.assertIsSatisfied(); }
From source file:zarg.bank.rest.web.BankRestController.java
@ExceptionHandler(ExecutionException.class) public ResponseEntity<String> handleIOException(final ExecutionException ex) { Throwable cause = ex; while (cause.getCause() != null) { cause = cause.getCause();/*from www . jav a 2 s . c om*/ } return new ResponseEntity<>("{\"error\": \"" + cause.getMessage() + "\"}", HttpStatus.BAD_REQUEST); }
From source file:com.ibm.jaql.lang.expr.core.ExpectExceptionFn.java
@Override public JsonValue eval(final Context context) throws Exception { try {/*from w w w.ja v a 2 s . c o m*/ JsonValue value = exprs[0].eval(context); throw new RuntimeException("Expected exception but found " + value); } catch (Exception ex) { if (exprs.length == 1) { LOG.info("any exception expected", ex); return EXPECTED; } Throwable cause = ex; while (cause.getCause() != null) { cause = cause.getCause(); } Class<?> causeClass = cause.getClass(); for (int i = 1; i < exprs.length; i++) { JsonString js = (JsonString) exprs[1].eval(context); Class<?> cls = ClassLoaderMgr.resolveClass(js.toString()); if (cls.isAssignableFrom(causeClass)) { LOG.info("exception was expected " + cls.getName().toString(), ex); return EXPECTED; } } throw new RuntimeException("expected an exception, but not this one", ex); } }
From source file:com.opendoorlogistics.core.utils.strings.Strings.java
/** * Gets the list of all messages from the exception and and the ancestor exception(s) that caused it. The list is returned in chronological order. * //from w w w .j a v a 2 s . co m * @param e * @return */ public static List<String> getExceptionMessages(Throwable e) { // get reversed list of causes so its chronological ArrayList<Throwable> causes = new ArrayList<>(); while (e != null) { causes.add(e); e = e.getCause(); } Collections.reverse(causes); // get the list of messages ArrayList<String> messages = new ArrayList<>(); ArrayList<String> ret = new ArrayList<>(); for (Throwable exception : causes) { if (isEmpty(exception.getMessage()) == false) { String msg = exception.getMessage(); // skip if part of the message has already been shown as its likely just the same message with // the exception class name added to the start boolean found = false; for (String shown : messages) { if (shown.length() > 3 && msg.toLowerCase().contains(shown.toLowerCase())) { found = true; break; } } if (!found) { // save to list of shown messages messages.add(msg); // only print the exception type if it gives the user some information if (exception.getClass() != Exception.class && exception.getClass() != RuntimeException.class) { ret.add("Exception of type \"" + exception.getClass().getSimpleName() + "\" : " + msg); } else { ret.add(msg); } } } } return ret; }
From source file:org.duracloud.snapshot.db.DatabaseInitializer.java
private Throwable getRootCause(Throwable throwable) { if (throwable.getCause() != null) { return getRootCause(throwable.getCause()); }//from w ww .j a v a2s . c om return throwable; }