List of usage examples for java.lang Throwable toString
public String toString()
From source file:com.ixora.common.ui.ShowExceptionDialog.java
/** * Sets the exception to show./*from www. j av a2 s . com*/ * @param ex */ public void setException(Throwable ex) { this.exception = ex; this.internalError = false; this.requiresHtmlRenderer = false; String msg = ex.getLocalizedMessage(); if (msg == null) { msg = ex.toString(); } if (ex instanceof AppException) { AppException aex = (AppException) ex; if (aex.isInternalAppError()) { internalError = true; logger.error(aex); setTitle(MessageRepository.get(Msg.COMMON_UI_TEXT_INTERNAL_APPLICATION_ERROR)); } else if (aex.requiresHtmlRenderer()) { requiresHtmlRenderer = true; } } else if (ex instanceof AppRuntimeException) { AppRuntimeException aex = (AppRuntimeException) ex; if (aex.isInternalAppError()) { internalError = true; logger.error(aex); setTitle(MessageRepository.get(Msg.COMMON_UI_TEXT_INTERNAL_APPLICATION_ERROR)); } else if (aex.requiresHtmlRenderer()) { requiresHtmlRenderer = true; } } if (internalError || requiresHtmlRenderer) { // prepare the html pane textExceptionLong.setContentType("text/html"); StringBuffer buff = new StringBuffer(); buff.append("<html>"); if (internalError) { buff.append(MessageRepository.get(Msg.COMMON_UI_TEXT_INTERNAL_APPLICATION_ERROR_SEND)); } buff.append("<p>"); buff.append(msg); buff.append("</p></html>"); msg = buff.toString(); setPreferredSize(largeSize); textExceptionLong.setText(msg); ((CardLayout) panel.getLayout()).show(panel, "long"); } else if (msg.length() > 80) { setPreferredSize(largeSize); textExceptionLong.setContentType("text/plain"); textExceptionLong.setText(msg); ((CardLayout) panel.getLayout()).show(panel, "long"); } else { textExceptionShort.setText(msg); // adjust the width if the text is too long Dimension d = textExceptionShort.getPreferredSize(); if (d.width > smallSize.width - 20) { setPreferredSize(new Dimension(d.width + 100, smallSize.height)); } else { setPreferredSize(smallSize); } ((CardLayout) panel.getLayout()).show(panel, "short"); } // if any other type be a little bit more verbose // for instance java.io.FileNotFoundException only // has in the message the name of the file // which is pretty useless so use here in the title // the last part of the exception's class name // as this is usually self explanatory // (this pattern is followed everywhere in // the jdk to avoid localization issues which is fair enough) // in general this situation shouldn't happen very // often as the basic exception should be wrapped // inside an AppException and given a meaningful message if (!(ex instanceof AppException) && !(ex instanceof AppRuntimeException)) { setTitle(getTitle() + " (" + getClassName(ex) + ")"); } }
From source file:com.liferay.portal.editor.fckeditor.receiver.impl.BaseCommandReceiver.java
public void createFolder(CommandArgument commandArgument, HttpServletRequest request, HttpServletResponse response) {// w w w . j av a 2 s . co m Document document = _createDocument(); Node rootNode = _createRoot(document, commandArgument.getCommand(), commandArgument.getType(), commandArgument.getCurrentFolder(), StringPool.BLANK); Element errorElement = document.createElement("Error"); rootNode.appendChild(errorElement); String returnValue = "0"; try { returnValue = createFolder(commandArgument); } catch (FCKException fcke) { Throwable cause = fcke.getCause(); returnValue = "110"; if (cause != null) { String causeString = GetterUtil.getString(cause.toString()); if (causeString.contains("DuplicateFolderNameException")) { returnValue = "101"; } else if (causeString.contains("FolderNameException")) { returnValue = "102"; } else if (causeString.contains("NoSuchGroupException") || causeString.contains("PrincipalException")) { returnValue = "103"; } else { throw fcke; } } } errorElement.setAttribute("number", returnValue); _writeDocument(document, response); }
From source file:com.ibm.mobilefirstplatform.clientsdk.cordovaplugins.core.CDVMFPRequest.java
/** * Packs a exception into a JSONObject/*from ww w. j av a 2 s . c o m*/ * * @param t Exception that could have caused the request to fail. null if no Exception thrown. * @return jsonException The String representation of the JSONObject */ private String packJavaThrowableToJSON(Throwable t) throws JSONException { mfpRequestLogger.debug("packJavaThrowableToJSON"); JSONObject jsonException = new JSONObject(); jsonException.put("errorCode", "Exception: request failure"); if (t.getMessage() != null) jsonException.put("errorDescription", t.getMessage()); else jsonException.put("errorDescription", t.toString()); return jsonException.toString(); }
From source file:com.summer.logger.LoggerPrinter.java
@Override public void e(Throwable throwable, String message, Object... args) { if (throwable != null && message != null) { message += " : " + Log.getStackTraceString(throwable); }/*from w ww. j a va2 s . c o m*/ if (throwable != null && message == null) { message = throwable.toString(); } if (message == null) { message = "No message/exception is set"; } log(ERROR, message, args); }
From source file:geogebra.common.kernel.statistics.RegressionMath.java
/** Does the Polynom regression for degree > 4 */ public final boolean doPolyN(GeoList gl, int degree) { error = false;//w w w. jav a2 s. c om geolist = gl; size = geolist.size(); getPoints(); // getPoints from geolist if (error) { return false; } try { /* * Old Jama version: long time=System.currentTimeMillis(); * makeMatrixArrays(degree); //make marray and yarray Matrix M=new * Matrix(marray); Matrix Y=new Matrix(yarray); Matrix * Par=M.solve(Y); //Par.print(3,3); * pararray=Par.getRowPackedCopy(); * System.out.println(System.currentTimeMillis()-time); */ makeMatrixArrays(degree); // make marray and yarray RealMatrix M = new Array2DRowRealMatrix(marray, false); DecompositionSolver solver = new QRDecompositionImpl(M).getSolver(); // time=System.currentTimeMillis(); RealMatrix Y = new Array2DRowRealMatrix(yarray, false); RealMatrix P = solver.solve(Y); pararray = P.getColumn(0); // System.out.println(System.currentTimeMillis()-time); // diff(pararray,par); } catch (Throwable t) { App.debug(t.toString()); error = true; } // try-catch. ToDo: A bit more fine-grained error-handling... return !error; }
From source file:at.itbh.bev.rest.client.BevRestClient.java
/** * Query the ReST endpoint using the command line arguments * /* ww w. j av a 2s . co m*/ * @param args * the command line arguments */ public void query(String[] args) { BevQueryExecutor executor = null; ResteasyClientBuilder clientBuilder = new ResteasyClientBuilder(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); int threadPoolSize = 1; if (line.hasOption("t")) { threadPoolSize = Integer.parseInt(line.getOptionValue("t")); } String postalCode = null; String place = null; String addressLine = null; String houseId = null; String radius = null; String longitude = null; String latitude = null; String separator = ";"; boolean enforceUnique = false; if (line.hasOption("z")) { postalCode = line.getOptionValue("z"); } if (line.hasOption("p")) { place = line.getOptionValue("p"); } if (line.hasOption("a")) { addressLine = line.getOptionValue("a"); } if (line.hasOption("i")) { houseId = line.getOptionValue("i"); } if (line.hasOption("radius")) { radius = line.getOptionValue("radius"); } if (line.hasOption("longitude")) { longitude = line.getOptionValue("longitude"); } if (line.hasOption("latitude")) { latitude = line.getOptionValue("latitude"); } if (line.hasOption("s")) { separator = line.getOptionValue("s"); } if (line.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar BevRestClient.jar", options, true); System.exit(0); } if (line.hasOption("u")) { enforceUnique = true; } if (line.hasOption("disable-certificate-validation")) { clientBuilder.disableTrustManager(); } if (!line.hasOption("proxy-port") && line.hasOption("proxy-host")) { throw new ParseException( "The option --proxy-host is only allowed in combination with the option --proxy-port."); } if (line.hasOption("proxy-port") && !line.hasOption("proxy-host")) { throw new ParseException( "The option --proxy-port is only allowed in combination with the option --proxy-host."); } if (line.hasOption("proxy-host") && line.hasOption("proxy-port")) { clientBuilder.defaultProxy(line.getOptionValue("proxy-host"), Integer.parseInt(line.getOptionValue("proxy-port"))); } OutputStreamWriter output; if (line.hasOption("o")) { output = new OutputStreamWriter(new FileOutputStream(line.getOptionValue("o"))); } else { output = new OutputStreamWriter(System.out); } // avoid concurrent access exceptions in the Apache http client clientBuilder.connectionPoolSize(threadPoolSize); executor = new BevQueryExecutor(clientBuilder.build(), line.getOptionValue("r"), threadPoolSize); CsvPreference csvPreference = new CsvPreference.Builder('"', Objects.toString(line.getOptionValue("s"), ";").toCharArray()[0], System.getProperty("line.separator")).build(); csvWriter = new CsvMapWriter(output, csvPreference, true); if (line.hasOption("b")) { ICsvMapReader mapReader = null; try { FileReader fileReader = new FileReader(line.getOptionValue("b")); mapReader = new CsvMapReader(fileReader, csvPreference); // calculate the output header (field names) final String[] header = mapReader.getHeader(true); ArrayList<String> tempFields = new ArrayList<>(Arrays.asList(defaultFieldNames)); for (int i = 0; i < header.length; i++) { if (!tempFields.contains(header[i])) { tempFields.add(header[i]); } } fieldNames = tempFields.toArray(new String[] {}); Map<String, String> inputData; List<Future<List<BevQueryResult>>> queryResults = new ArrayList<>(); while ((inputData = mapReader.read(header)) != null) { queryResults .add(executor.query(inputData.get(INPUT_POSTAL_CODE), inputData.get(INPUT_PLACE), inputData.get(INPUT_ADDRESS_LINE), inputData.get(INPUT_HOUSE_ID), inputData.get(INPUT_LONGITUDE), inputData.get(INPUT_LATITUDE), inputData.get(INPUT_RADIUS), inputData.get(INPUT_ENFORCE_UNIQUE) == null ? false : Boolean.parseBoolean(inputData.get(INPUT_ENFORCE_UNIQUE)), inputData)); } csvWriter.writeHeader(fieldNames); for (Future<List<BevQueryResult>> queryResult : queryResults) { List<BevQueryResult> results = queryResult.get(); outputResults(separator, results); } } finally { if (mapReader != null) { mapReader.close(); } } } else { fieldNames = defaultFieldNames; Map<String, String> inputData = new HashMap<String, String>(); Future<List<BevQueryResult>> queryResult = executor.query(postalCode, place, addressLine, houseId, longitude, latitude, radius, enforceUnique, inputData); try { List<BevQueryResult> results = queryResult.get(); if (enforceUnique && results.size() == 1) { if (!results.get(0).getFoundMatch()) throw new Exception("No unique result found."); } outputResults(separator, results); } catch (ExecutionException e) { throw e.getCause(); } } } catch (ParseException exp) { System.out.println(exp.getMessage()); System.out.println(); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar BevRestClient.jar", options, true); System.exit(-2); } catch (BevRestException e) { System.err.println(e.toString()); System.exit(e.getErrorCode()); } catch (JsonProcessingException e) { System.err.println(e.toString()); System.exit(-3); } catch (IOException e) { System.err.println(e.toString()); System.exit(-4); } catch (Throwable t) { System.err.println(t.toString()); t.printStackTrace(); System.exit(-1); } finally { if (csvWriter != null) { try { csvWriter.close(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } } if (executor != null) { executor.dispose(); } } }
From source file:eionet.cr.api.xmlrpc.XmlRpcServices.java
@Override public Vector getEntries(Hashtable criteria) throws CRException { if (logger.isInfoEnabled()) { logger.info("Entered " + Thread.currentThread().getStackTrace()[1].getMethodName()); }//w w w. j av a2 s .c om Vector result = new Vector(); try { SearchResultDTO<SubjectDTO> searchResult = DAOFactory.get().getDao(SearchDAO.class) .searchByFilters(criteria, false, PagingRequest.create(1, MAX_RESULTS), null, null, true); Collection<SubjectDTO> subjects = searchResult.getItems(); if (subjects != null) { for (Iterator<SubjectDTO> iter = subjects.iterator(); iter.hasNext();) { SubjectDTO subjectDTO = iter.next(); Hashtable<String, Vector<String>> predicatesTable = new Hashtable<String, Vector<String>>(); for (Iterator<String> predicatesIter = subjectDTO.getPredicates().keySet() .iterator(); predicatesIter.hasNext();) { String predicate = predicatesIter.next(); predicatesTable.put(predicate, new Vector<String>(getLiteralValues(subjectDTO, predicate))); } if (!predicatesTable.isEmpty()) { Hashtable<String, Hashtable> subjectTable = new Hashtable<String, Hashtable>(); subjectTable.put(subjectDTO.getUri(), predicatesTable); result.add(subjectTable); } } } } catch (Throwable t) { t.printStackTrace(); if (t instanceof CRException) { throw (CRException) t; } else { throw new CRException(t.toString(), t); } } return result; }
From source file:io.bitsquare.gui.main.funds.withdrawal.WithdrawalView.java
@Override public void initialize() { tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); tableView.setPlaceholder(new Label("No funds are available for withdrawal")); tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); setAddressColumnCellFactory();// w w w . j a va 2 s.co m setBalanceColumnCellFactory(); setSelectColumnCellFactory(); addressColumn.setComparator((o1, o2) -> o1.getAddressString().compareTo(o2.getAddressString())); balanceColumn.setComparator((o1, o2) -> o1.getBalance().compareTo(o2.getBalance())); balanceColumn.setSortType(TableColumn.SortType.DESCENDING); tableView.getSortOrder().add(balanceColumn); balanceListener = new BalanceListener() { @Override public void onBalanceChanged(Coin balance, Transaction tx) { updateList(); } }; amountListener = (observable, oldValue, newValue) -> { if (amountTextField.focusedProperty().get()) { try { senderAmountAsCoinProperty.set(formatter.parseToCoin(amountTextField.getText())); } catch (Throwable t) { log.error("Error at amountTextField input. " + t.toString()); } } }; amountFocusListener = (observable, oldValue, newValue) -> { if (oldValue && !newValue) { if (senderAmountAsCoinProperty.get().isPositive()) amountTextField.setText(formatter.formatCoin(senderAmountAsCoinProperty.get())); else amountTextField.setText(""); } }; }
From source file:eionet.cr.api.xmlrpc.XmlRpcServices.java
@Override public Vector getXmlFilesBySchema(String schemaIdentifier) throws CRException { if (logger.isInfoEnabled()) { logger.info("Entered " + Thread.currentThread().getStackTrace()[1].getMethodName()); }//w w w .j a v a 2 s . c o m Vector result = new Vector(); try { if (!StringUtils.isBlank(schemaIdentifier)) { SearchDAO searchDao = DAOFactory.get().getDao(SearchDAO.class); Map<String, String> criteria = new HashMap<String, String>(); criteria.put(Predicates.CR_SCHEMA, schemaIdentifier); SearchResultDTO<SubjectDTO> searchResult = searchDao.searchByFilters(criteria, false, null, null, null, true); int subjectCount = searchResult.getMatchCount(); logger.debug(getClass().getSimpleName() + ".getXmlFilesBySchema(" + schemaIdentifier + "), " + subjectCount + " subjects found in total"); List<SubjectDTO> subjects = searchResult.getItems(); if (subjects != null && !subjects.isEmpty()) { for (SubjectDTO subjectDTO : subjects) { String lastModif = subjectDTO.getObjectValue(Predicates.CR_LAST_MODIFIED); Hashtable hashtable = new Hashtable(); hashtable.put("uri", subjectDTO.getUri()); hashtable.put("lastModified", lastModif == null ? "" : lastModif.trim()); result.add(hashtable); } } } } catch (Throwable t) { t.printStackTrace(); if (t instanceof CRException) { throw (CRException) t; } else { throw new CRException(t.toString(), t); } } return result; }
From source file:com.eviware.soapui.SoapUI.java
public static void logError(Throwable e, String message) { String msg = e.getMessage();/*from w w w . j a v a2 s .co m*/ if (msg == null) msg = e.toString(); log.error("An error occured [" + msg + "], see error log for details"); try { if (message != null) errorLog.error(message); errorLog.error(e.toString(), e); } catch (OutOfMemoryError e1) { e1.printStackTrace(); System.gc(); } if (!isStandalone() || "true".equals(System.getProperty("soapui.stacktrace"))) e.printStackTrace(); }