List of usage examples for java.lang Throwable getLocalizedMessage
public String getLocalizedMessage()
From source file:com.runwaysdk.controller.ErrorUtility.java
private static void prepareThrowable(Throwable t, HttpServletRequest req) { String localizedMessage = t.getLocalizedMessage(); req.setAttribute(ErrorUtility.ERROR_MESSAGE, localizedMessage); if (t instanceof ProgrammingErrorExceptionDTO) { try {/*from w ww.j a v a 2 s . c om*/ ProgrammingErrorExceptionDTO pee = (ProgrammingErrorExceptionDTO) t; String developerMessage = pee.getDeveloperMessage(); req.setAttribute(ErrorUtility.DEVELOPER_MESSAGE, developerMessage); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (t instanceof RuntimeException) { throw (RuntimeException) t; } }
From source file:com.tesora.dve.common.PEBaseTest.java
protected static void failWithStackTrace(Throwable e, String message) { fail((message != null && !message.isEmpty() ? message : "Should not throw exception") + ": " + e.getLocalizedMessage() + "\nTrace: " + PEStringUtils.toString(e)); }
From source file:org.apache.phoenix.util.ServerUtil.java
public static long parseTimestampFromRemoteException(Throwable t) { String message = t.getLocalizedMessage(); if (message != null) { // If the message matches the standard pattern, recover the SQLException and throw it. Matcher matcher = PATTERN_FOR_TS.matcher(t.getLocalizedMessage()); if (matcher.find()) { String tsString = matcher.group(1); if (tsString != null) { return Long.parseLong(tsString); }// ww w . jav a 2 s . c o m } } return HConstants.LATEST_TIMESTAMP; }
From source file:org.apache.phoenix.util.ServerUtil.java
private static SQLException parseRemoteException(Throwable t) { String message = t.getLocalizedMessage(); if (message != null) { // If the message matches the standard pattern, recover the SQLException and throw it. Matcher matcher = PATTERN.matcher(t.getLocalizedMessage()); if (matcher.find()) { int statusCode = Integer.parseInt(matcher.group(1)); SQLExceptionCode code = SQLExceptionCode.fromErrorCode(statusCode); if (code.equals(SQLExceptionCode.HASH_JOIN_CACHE_NOT_FOUND)) { Matcher m = HASH_JOIN_EXCEPTION_PATTERN.matcher(t.getLocalizedMessage()); if (m.find()) { return new HashJoinCacheNotFoundException(Long.parseLong(m.group(1))); }//from w ww . jav a 2 s . c o m } return new SQLExceptionInfo.Builder(code).setMessage(matcher.group()).setRootCause(t).build() .buildException(); } } return null; }
From source file:uk.ac.ucl.cs.cmic.giftcloud.util.GiftCloudUtils.java
/** * Returns a list of resources matching the specified pattern * * @param pattern//w ww .j a v a 2 s . co m * @return */ public static List<Resource> getMatchingResources(final String pattern, final GiftCloudReporter reporter) { try { return Arrays.asList(new PathMatchingResourcePatternResolver().getResources(pattern)); } catch (Throwable throwable) { reporter.silentLogException(throwable, "Error when fetching resources: " + throwable.getLocalizedMessage()); return new ArrayList<Resource>(); } }
From source file:it.geosolutions.filesystemmonitor.neutral.monitorpolling.GBFileSystemMonitorJob.java
/** * Try to build the Observer using informations stored into the JobDataMap * // w w w . j a v a 2s .c o m * @note this method is not sync * @param jdm * @return * @throws JobExecutionException */ private static FileAlterationObserver buildObserver(JobDataMap jdm) throws JobExecutionException { FileAlterationObserver observer = null; final GBEventNotifier notifier; // first time build try { final File directory = new File(jdm.getString(FileSystemMonitorSPI.SOURCE_KEY)); observer = new FileAlterationObserver(directory, new WildcardFileFilter(jdm.getString(FileSystemMonitorSPI.WILDCARD_KEY))); notifier = (GBEventNotifier) jdm.get(EVENT_NOTIFIER_KEY); final FileAlterationListener fal = new GBFileAlterationListener(notifier); observer.addListener(fal); } catch (ClassCastException cce) { // ClassCastException - if the identified object is not a String. throw exceptionPolicy(ExcPolicy.IMMEDIATELY, "The identified object is not a String.\n" + cce.getLocalizedMessage(), cce); } catch (NullPointerException npe) { // NullPointerException - If the pathname argument is null throw exceptionPolicy(ExcPolicy.IMMEDIATELY, "The pathname argument is null.\n" + npe.getLocalizedMessage(), npe); } catch (IllegalArgumentException iae) { // IllegalArgumentException - if the pattern is null throw exceptionPolicy(ExcPolicy.IMMEDIATELY, "The pattern is null.\n" + iae.getLocalizedMessage(), iae); } catch (Throwable e) { throw exceptionPolicy(ExcPolicy.IMMEDIATELY, "Probably the consumer cannot start.\n" + e.getLocalizedMessage(), e); } try { observer.initialize(); } catch (Throwable t) { throw exceptionPolicy(ExcPolicy.IMMEDIATELY, "An error occurs.\n" + t.getLocalizedMessage(), t); } jdm.put(OBSERVER_KEY, observer); return observer; }
From source file:com.examples.with.different.packagename.concolic.MathRuntimeException.java
/** * Constructs a new <code>IOException</code> with specified nested * <code>Throwable</code> root cause. * <p>This factory method allows chaining of other exceptions within an * <code>IOException</code> even for Java 5. The constructor for * <code>IOException</code> with a cause parameter was introduced only * with Java 6.</p>//from ww w .j av a 2 s .co m * @param rootCause the exception or error that caused this exception * to be thrown. * @return built exception */ public static IOException createIOException(final Throwable rootCause) { IOException ioe = new IOException(rootCause.getLocalizedMessage()); ioe.initCause(rootCause); return ioe; }
From source file:com.examples.with.different.packagename.concolic.MathRuntimeException.java
/** * Constructs a new <code>IllegalArgumentException</code> with specified nested * <code>Throwable</code> root cause. * @param rootCause the exception or error that caused this exception * to be thrown.//w w w. j a va2 s.c om * @return built exception */ public static IllegalArgumentException createIllegalArgumentException(final Throwable rootCause) { IllegalArgumentException iae = new IllegalArgumentException(rootCause.getLocalizedMessage()); iae.initCause(rootCause); return iae; }
From source file:it.geosolutions.tools.io.file.IOUtils.java
/** * Optimize version of copy method for file channels. * //w w w . ja va 2 s .c o m * @param bufferSize * size of the temp buffer to use for this copy. * @param source * the source {@link ReadableByteChannel}. * @param destination * the destination {@link WritableByteChannel};. * @throws IOException * in case something bad happens. */ public static void copyFileChannel(int bufferSize, FileChannel source, FileChannel destination) throws IOException { Objects.notNull(source, destination); if (!source.isOpen() || !destination.isOpen()) throw new IllegalStateException("Source and destination channels must be open."); FileLock lock = null; try { lock = destination.lock(); final long sourceSize = source.size(); long pos = 0; while (pos < sourceSize) { // read and flip final long remaining = (sourceSize - pos); final int mappedZoneSize = remaining >= bufferSize ? bufferSize : (int) remaining; destination.transferFrom(source, pos, mappedZoneSize); // update zone pos += mappedZoneSize; } } finally { if (lock != null) { try { lock.release(); } catch (Throwable t) { if (LOGGER.isInfoEnabled()) LOGGER.info(t.getLocalizedMessage(), t); } } } }
From source file:org.apache.openejb.math.MathRuntimeException.java
/** * Constructs a new <code>IOException</code> with specified nested * <code>Throwable</code> root cause. * <p>This factory method allows chaining of other exceptions within an * <code>IOException</code> even for Java 5. The constructor for * <code>IOException</code> with a cause parameter was introduced only * with Java 6.</p>/* ww w .j a va 2 s . c o m*/ * * @param rootCause the exception or error that caused this exception * to be thrown. * @return built exception */ public static IOException createIOException(final Throwable rootCause) { final IOException ioe = new IOException(rootCause.getLocalizedMessage()); ioe.initCause(rootCause); return ioe; }