List of usage examples for java.lang Throwable getMessage
public String getMessage()
From source file:com.kixeye.chassis.transport.ExceptionServiceErrorMapper.java
/** * Maps an exception to an error.// w ww. j a va2s . c om * * @param ex * @return */ public static ServiceError mapException(Throwable ex) { ServiceError error = null; if (ex instanceof ServiceException) { ServiceException servEx = (ServiceException) ex; error = servEx.error; } else if (ex instanceof MethodArgumentNotValidException) { MethodArgumentNotValidException validationEx = (MethodArgumentNotValidException) ex; List<String> errors = Lists.newArrayList(); for (ObjectError objError : validationEx.getBindingResult().getAllErrors()) { errors.add( objError.getObjectName() + ":" + objError.getCode() + ":" + objError.getDefaultMessage()); } error = new ServiceError(VALIDATION_ERROR_CODE, Joiner.on("|").join(errors)); } else { error = new ServiceError(UNKNOWN_ERROR_CODE, ex.getMessage()); } return error; }
From source file:com.msopentech.o365.outlookServices.OutlookServicesMethodsImpl.java
/** * Adds default callback that send future's result back to plugin * This is specially for raw SDK methods which returns a string typed future * * @param future Future to add callback to * @param context Plugin context used to send future result back to plugin *///w w w .j a v a 2 s .co m static void addRawCordovaCallback(final ListenableFuture<String> future, final CallbackContext context) { Futures.addCallback(future, new FutureCallback<String>() { @Override public void onSuccess(String s) { PluginResult result = s == null ? new PluginResult(PluginResult.Status.OK) : new PluginResult(PluginResult.Status.OK, s); context.sendPluginResult(result); } @Override public void onFailure(Throwable throwable) { String error = throwable.getMessage(); if (throwable instanceof ODataException) { String response = new String(((ODataException) throwable).getODataResponse().getPayload()); // since error object is encapsulated into response's object // try to get it from response and return instead of raw throwable's message try { JSONObject errorMessage = new JSONObject(response); error = errorMessage.get("error").toString(); } catch (JSONException ignored) { } } context.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } }); }
From source file:bb.io.TarUtil.java
/** * Writes path as a new TarArchiveEntry to tarArchiveOutputStream. * If path is a normal file, then next writes path's data to tarArchiveOutputStream. * <p>/*from w w w .jav a2s . co m*/ * If path is a directory, then this method additionally calls itself on the contents * (thus recursing thru the entire directory tree). * <p> * <b>Warning</b>: several popular programs (e.g. winzip) fail to display mere directory entries. * Furthermore, if just a directory entry is present (i.e. it is empty), they also may fail * to create a new empty directoy when extracting the TAR file's contents. * These are bugs in their behavior. * <p> * An optional FileFilter can be supplied to screen out paths that would otherwise be archived. * <p> * <i>This method does not close tarArchiveOutputStream:</i> that is the responsibility of the caller. * <p> * The caller also must take on the responsibility to not do anything stupid, like write * path more than once, or have the path be the same File that tarArchiveOutputStream is writing to. * <p> * @param path the File to archive * @param fileParent the FileParent for path * @param tarArchiveOutputStream the TarArchiveOutputStream that will write the archive data to * @param filter a FileFilter that can use to screen out certain files from being written to the archive; may be null (so everything specified by path gets archived) * @throws Exception if any Throwable is caught; the Throwable is stored as the cause, and the message stores path's information; * here are some of the possible causes: * <ol> * <li>IllegalArgumentException if path fails {@link #isTarable isTarable}</li> * <li>SecurityException if a security manager exists and its SecurityManager.checkRead method denies read access to path</li> * <li>IOException if an I/O problem occurs</li> * </ol> */ private static void archive(File path, FileParent fileParent, TarArchiveOutputStream tarArchiveOutputStream, FileFilter filter) throws Exception { try { if ((filter != null) && !filter.accept(path)) return; if (!isTarable(path)) throw new IllegalArgumentException("path = " + path.getPath() + " failed isTarable"); if (giveUserFeedback) ConsoleUtil.overwriteLine("TarUtil.archive: " + path.getPath()); TarArchiveEntry entry = new TarArchiveEntry(path); entry.setName(fileParent.getRelativePath(path, '/')); // Note: getRelativePath will ensure that '/' is the path separator and that directories end with '/' tarArchiveOutputStream.putNextEntry(entry); if (path.isFile()) readInFile(path, tarArchiveOutputStream); tarArchiveOutputStream.closeEntry(); if (path.isDirectory()) { for (File fileChild : DirUtil.getContents(path, null)) { // supply null, since we test at beginning of this method (supplying filter here will just add a redundant test) archive(fileChild, fileParent, tarArchiveOutputStream, filter); } } } catch (Throwable t) { String preface = "See cause for the underlying Throwable; happened for path = "; if ((t instanceof Exception) && (t.getMessage().startsWith(preface))) throw (Exception) t; // CRITICAL: see if t was actually the wrapping Exception generated by a subsequent recursive call to this method, and if so simply rethrow it unmodified to avoid excessive exception chaining throw new Exception(preface + (path != null ? path.getPath() : "<null>"), t); } }
From source file:net.rim.ejde.internal.util.PackageUtils.java
static public String parseFileForPackageId(File file) { if ((null == file) || file.isDirectory() || !file.exists()) { String msg = NLS.bind(Messages.PackageUtils_UNDEFINED_FILE_ERROR_MSG, IConstants.EMPTY_STRING); _logger.error(msg);// ww w . j a v a2s. c o m throw new RuntimeException(msg); } String packageId = null, filePath = file.getAbsolutePath(), line, token; BufferedReader bufferedReader = null; StringTokenizer tokenizer; try { if (PackageUtils.hasRRHExtension(filePath) || PackageUtils.hasRRCExtension(filePath) || PackageUtils.hasJavaExtension(filePath)) { bufferedReader = new BufferedReader(new FileReader(file)); if (!bufferedReader.ready()) { throw new RuntimeException( NLS.bind(Messages.PackageUtils_EMPTY_FILE_ERROR_MSG, file.getPath())); } while (null != (line = bufferedReader.readLine())) { // pull lines from file till find the one containing // package definition line = line.trim(); if ((0 < line.length()) && // criterion to recognize a // package declaration line.startsWith("package")) { while (!line.contains(IConstants.SEMICOLON_MARK)) { line = line + bufferedReader.readLine(); } tokenizer = new StringTokenizer(line); while (tokenizer.hasMoreTokens()) { // pull the package tokens token = tokenizer.nextToken(); if (!"package".equals(token)) { if (token.contains(IConstants.SEMICOLON_MARK)) { token = token.replaceAll(IConstants.SEMICOLON_MARK, IConstants.EMPTY_STRING); } packageId = StringUtils.isNotBlank(token) ? token : IConstants.EMPTY_STRING; break; } // end pulling of eventual package tokens } } if (null != packageId) { // file break; } } } else { throw new RuntimeException( NLS.bind(Messages.PackageUtils_UNSUPPORTED_FILE_ERROR_MSG, file.getPath())); } } catch (Throwable t) { _logger.debug(t.getMessage(), t); } finally { if (null != bufferedReader) { try { bufferedReader.close(); } catch (IOException e) { _logger.error(e.getMessage(), e); } } } return packageId; }
From source file:com.microsoft.tfs.client.common.ui.framework.diagnostics.InternalSupportUtils.java
public static boolean doExport(final Shell shell, final DataProviderCollection dataProviderCollection, final File outputFile) { final ExportRunnable runnable = new ExportRunnable(dataProviderCollection, outputFile); Throwable error = null; final DeferredProgressMonitorDialogContext context = new DeferredProgressMonitorDialogContext(shell, 500); try {/*from w ww . j a v a 2 s . com*/ context.run(true, true, runnable); error = runnable.getError(); } catch (final InvocationTargetException e) { error = e.getTargetException(); } catch (final InterruptedException e) { return false; } if (runnable.wasCancelled()) { return false; } if (error != null) { log.error(error); final String messageFormat = Messages.getString("InternalSupportUtils.ExportErrorStatusFormat"); //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, error.getMessage()); final Status status = new Status(IStatus.ERROR, TFSCommonUIClientPlugin.PLUGIN_ID, IStatus.OK, message, error); ErrorDialog.openError(shell, Messages.getString("InternalSupportUtils.ErrorDialogTitle"), //$NON-NLS-1$ error.getMessage(), status); return false; } return true; }
From source file:kr.co.aim.nanoframe.exception.ErrorSignal.java
public static nanoFrameErrorSignal getNotifyException(Throwable e) { if (e instanceof nanoFrameErrorSignal) return (nanoFrameErrorSignal) e; else if (e instanceof InvocationTargetException) { Throwable cause = ((InvocationTargetException) e).getTargetException(); return getNotifyException(cause); } else if (e instanceof SQLException) { return getNotifyException((SQLException) e, null, null); } else if (e instanceof DataAccessException) { return getNotifyException((DataAccessException) e); } else if (e instanceof NestedRuntimeException) { Throwable cause = ((NestedRuntimeException) e).getMostSpecificCause(); if (cause != null) return new nanoFrameErrorSignal(ErrorSignal.UnexprectedSignal, e.getMessage(), e); else {//from w w w .jav a2s . c o m cause = e.getCause(); if (cause != null) return new nanoFrameErrorSignal(ErrorSignal.UnexprectedSignal, e.getMessage(), e); } } return new nanoFrameErrorSignal(ErrorSignal.UnexprectedSignal, e.getMessage(), e); }
From source file:com.stimulus.archiva.service.MessageService.java
private static File copyToTemp(InputStream stream) throws ArchiveException { File tempFile = null;/* w w w . j a va 2 s . c om*/ try { tempFile = File.createTempFile("incoming", ".eml"); logger.debug("storing archive data in temp file {tempFile='" + tempFile.getPath() + "'}"); IOUtil.copy(stream, new FileOutputStream(tempFile)); logger.debug("temp file written {tempFile='" + tempFile.getPath() + "'}"); return tempFile; } catch (Throwable e) { tempFile.delete(); try { stream.close(); } catch (Exception e2) { } throw new ArchiveException("failed to retrieve message for archiving:" + e.getMessage(), e, logger, ArchiveException.RecoveryDirective.RETRYLATER); } }
From source file:com.seer.datacruncher.utils.generic.CommonUtils.java
public static String getExceptionMessage(Exception ex) { String msg = ex.getMessage(); if (msg != null) { return msg; } else {//from ww w.j ava 2s. c o m try { msg = ""; StackTraceElement[] trace = ex.getStackTrace(); Throwable e1 = ex.getCause(); if (e1 != null) { for (int i = 0; i < trace.length; i++) { if (e1 != null) { msg = e1.getMessage(); if (msg != null) { System.out.println(msg); break; } else { e1 = e1.getCause(); } } } } return msg; } catch (Exception e) { return msg; } } }
From source file:net.cbtltd.server.PartyService.java
/** * Updates the progress of users towards certain goals. * Executed periodically by the RazorServer scheduler. *//*www . j a va 2 s . c o m*/ public static final void progress() { LOG.debug("PartyService progress"); SqlSession sqlSession = RazorServer.openSession(); try { sqlSession.getMapper(PartyMapper.class).progressdelete(); sqlSession.getMapper(PartyMapper.class).progressactivitymax(); sqlSession.getMapper(PartyMapper.class).progressage(); sqlSession.getMapper(PartyMapper.class).progressagemax(); sqlSession.getMapper(PartyMapper.class).progressconfirm(); sqlSession.getMapper(PartyMapper.class).progresscreator(); sqlSession.getMapper(PartyMapper.class).progresscreatormax(); // sqlSession.getMapper(PartyMapper.class).progressvalue(); // sqlSession.getMapper(PartyMapper.class).progressvaluemax(); sqlSession.commit(); } catch (Throwable x) { sqlSession.rollback(); LOG.error(x.getMessage()); } finally { sqlSession.close(); } }
From source file:net.cbtltd.server.PartyService.java
/** * Executes the OrganizationUpdate action to update a property manager instance. * * @param sqlSession the current SQL session. * @param action the action to be executed. * @return the organization//from www . j a v a 2 s.co m */ public static final Organization execute(SqlSession sqlSession, OrganizationUpdate action) { //LOG.debug("OrganizationUpdate " + action); try { if (action.hasPassword()) { String password = Party.decrypt(action.getPassword()); action.setPassword(BCrypt.hashpw(password, BCrypt.gensalt())); } else { action.setPassword(null); } sqlSession.getMapper(PartyMapper.class).update(action); RelationService.replace(sqlSession, Relation.PARTY_VALUE, action.getId(), action.getValues()); RelationService.replace(sqlSession, Relation.ORGANIZATION_CURRENCY, action.getId(), action.getCurrencies()); RelationService.replace(sqlSession, Relation.ORGANIZATION_LANGUAGE, action.getId(), action.getLanguages()); TextService.update(sqlSession, action.getTexts()); WorkflowService.update(sqlSession, action.getWorkflows()); if (action.hasOldstate(Party.INITIAL) && action.getNeedToSendEmail()) { EmailService.partyCreate(action); } MonitorService.update(sqlSession, Data.Origin.CONSOLE, NameId.Type.Party, action); } catch (Throwable x) { sqlSession.rollback(); LOG.error(x.getMessage()); } return action; }