List of usage examples for java.lang Throwable toString
public String toString()
From source file:it.cnr.icar.eric.client.ui.thin.OutputExceptions.java
/** * Log exceptions and display them to user in a consistent fashion. * * @param log Log where error or warning should be output * @param logMsg Context message to log with t * @param displayMsg Context message to display to user with t * @param t Throwable to log about and optionally display * @param display Output information about this Throwable on page? * @param warning If true, log warning rather than error *//*from w w w . ja v a 2 s . co m*/ private static void display(Log log, String logMsg, String displayMsg, Throwable t, boolean display, boolean warning) { // When not given a Msg, should we provide context for cause? boolean needContext = (null != t.getMessage() && null != t.getCause()); // Log a fair amount of information unconditionally if (null == logMsg && null != displayMsg) { logMsg = displayMsg; } if (log.isDebugEnabled()) { // Include full traceback in logging output if (null == logMsg) { if (warning) { log.warn(t.toString(), t); } else { log.error(t.toString(), t); } } else { if (warning) { log.warn(logMsg, t); } else { log.error(logMsg, t); } } } else { if (null == logMsg) { if (needContext) { if (warning) { log.warn(t.toString()); } else { log.error(t.toString()); } } } else { if (warning) { log.warn(logMsg); } else { log.error(logMsg); } } if (warning) { log.error(getCause(t, true)); } else { log.error(getCause(t, true)); } } // Conditionally display a subset of the above information to the user if (display) { FacesContext context = FacesContext.getCurrentInstance(); FacesMessage.Severity severity = (warning ? FacesMessage.SEVERITY_ERROR : FacesMessage.SEVERITY_WARN); if (null == displayMsg && null != logMsg) { displayMsg = logMsg; } if (null == displayMsg) { if (needContext) { context.addMessage(null, new FacesMessage(severity, goodMessage(t), null)); } } else { context.addMessage(null, new FacesMessage(severity, displayMsg, null)); } context.addMessage(null, new FacesMessage(severity, getCause(t, false), null)); } }
From source file:it.cnr.icar.eric.client.ui.thin.OutputExceptions.java
/** * Choose a string about Throwable which ignores generic class names * * @param t Throwable of interest//from ww w .j ava 2s.c om * t.getMessage() must be non-null when this method is used * @return String message about t */ private static String goodMessage(Throwable t) { String msg; String className = t.getClass().getName(); // TODO: may want to add to this list over time if ("java.lang.Error".equals(className) || "java.lang.Exception".equals(className) || "java.lang.Throwable".equals(className) || "javax.xml.bind.JAXBException".equals(className) || "javax.xml.registry.JAXRException".equals(className) || "javax.xml.registry.RegistryException".equals(className) || "javax.xml.rpc.JAXRPCException".equals(className)) { msg = t.getMessage(); } else { msg = t.toString(); } return msg; }
From source file:main.java.vasolsim.common.GenericUtils.java
public static String exceptionToString(@Nonnull Throwable t) { StringBuilder out = new StringBuilder(); out.append("Ex: ").append(t.toString()).append("\n"); out.append("Cause: ").append(t.getCause()).append("\n"); out.append("Message: ").append(t.getMessage()).append("\n\n"); out.append("StackTrace:\n").append(ExceptionUtils.getStackTrace(t)); out.append("---------- END ----------"); return out.toString(); }
From source file:com.netscape.cms.servlet.csadmin.CertUtil.java
public static PKCS10 getPKCS10(IConfigStore config, String prefix, Cert certObj, Context context) throws IOException { String certTag = certObj.getCertTag(); X509Key pubk = null;//from w w w . j a va 2 s . com try { String pubKeyType = config.getString(prefix + certTag + ".keytype"); String algorithm = config.getString(prefix + certTag + ".keyalgorithm"); if (pubKeyType.equals("rsa")) { String pubKeyModulus = config.getString(prefix + certTag + ".pubkey.modulus"); String pubKeyPublicExponent = config.getString(prefix + certTag + ".pubkey.exponent"); pubk = CryptoUtil.getPublicX509Key(CryptoUtil.string2byte(pubKeyModulus), CryptoUtil.string2byte(pubKeyPublicExponent)); } else if (pubKeyType.equals("ecc")) { String pubKeyEncoded = config.getString(prefix + certTag + ".pubkey.encoded"); pubk = CryptoUtil.getPublicX509ECCKey(CryptoUtil.string2byte(pubKeyEncoded)); } else { logger.error("CertUtil: getPKCS10() - " + "public key type is unsupported: " + pubKeyType); throw new IOException("Public key type is unsupported: " + pubKeyType); } if (pubk != null) { logger.debug("CertUtil: got public key"); } else { logger.error("CertUtil: error getting public key null"); throw new IOException("public key is null"); } // get private key String privKeyID = config.getString(prefix + certTag + ".privkey.id"); byte[] keyIDb = CryptoUtil.decodeKeyID(privKeyID); PrivateKey privk = CryptoUtil.findPrivateKeyFromID(keyIDb); if (privk != null) { logger.debug("CertUtil: got private key"); } else { logger.warn("CertUtil: error getting private key null"); } // construct cert request String dn = config.getString(prefix + certTag + ".dn"); return CryptoUtil.createCertificationRequest(dn, pubk, privk, algorithm); } catch (Throwable e) { logger.error("CertUtil: getPKCS10: " + e, e); if (context != null) { context.put("errorString", e.toString()); } throw new IOException(e); } }
From source file:com.example.android.cardreader.MainActivity.java
public static void checkin(User u) { usr = u;//from ww w .java 2s .c om new MultiThread(new Runnable() { @Override public void run() { SyncHttpClient client = new SyncHttpClient(); RequestParams params = new RequestParams(); params.put("nfctag", usr.rfid); params.put("event_id", "1"); params.setUseJsonStreamer(true); System.out.println("rfid = " + usr.rfid); client.post(Globals.start + "/event/checkin", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { String result = new String(responseBody); System.out.println("Posted res: " + result); } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { System.out.println("Posted failed: " + error.toString()); } }); } }).executeOnExecutor(Executors.newSingleThreadExecutor()); }
From source file:com.example.android.cardreader.MainActivity.java
public static void getUsers(int eventId) { System.out.println("Getting Users."); AsyncHttpClient client = new AsyncHttpClient(); client.get(Globals.start + "/event/get-registered/" + eventId, new AsyncHttpResponseHandler() { @Override/*from w w w . java2 s.com*/ public void onSuccess(int i, cz.msebera.android.httpclient.Header[] headers, byte[] bytes) { String response = new String(bytes); System.out.println("Response=" + response); parseRegistered(response); } @Override public void onFailure(int i, cz.msebera.android.httpclient.Header[] headers, byte[] bytes, Throwable throwable) { System.out.println("Failed with " + throwable.toString()); } }); client.get(Globals.start + "/event/get-checked-in/" + eventId, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, cz.msebera.android.httpclient.Header[] headers, byte[] bytes) { String response = new String(bytes); System.out.println("Response=" + response); parseCheckedIn(response); } @Override public void onFailure(int i, cz.msebera.android.httpclient.Header[] headers, byte[] bytes, Throwable throwable) { System.out.println("Failed with " + throwable.toString()); } }); }
From source file:com.example.android.cardreader.MainActivity.java
public static void refreshUsers() { System.out.println("Refreshing Users."); refreshClient = new AsyncHttpClient(); refreshClient.get(Globals.start + "/event/get-registered/" + 1, new AsyncHttpResponseHandler() { @Override// ww w . j av a 2 s . c o m public void onSuccess(int i, cz.msebera.android.httpclient.Header[] headers, byte[] bytes) { String response = new String(bytes); System.out.println("Response=" + response); Globals.allUsers.clear(); Globals.pending.clear(); parseRegistered(response); refreshClient.get(Globals.start + "/event/get-checked-in/" + 1, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, cz.msebera.android.httpclient.Header[] headers, byte[] bytes) { String response = new String(bytes); System.out.println("Response=" + response); Globals.checkedIn.clear(); parseCheckedIn(response); } @Override public void onFailure(int i, cz.msebera.android.httpclient.Header[] headers, byte[] bytes, Throwable throwable) { System.out.println("Failed with " + throwable.toString()); } }); } @Override public void onFailure(int i, cz.msebera.android.httpclient.Header[] headers, byte[] bytes, Throwable throwable) { System.out.println("Failed with " + throwable.toString()); } }); }
From source file:it.cnr.icar.eric.client.ui.thin.OutputExceptions.java
/** * Find a string which should provide most information about a Throwable. * * @param t Throwable of interest//w w w . j av a 2 s. c o m * @param forLog If true, return more information; going into log * @return String message describing original cause for t */ private static String getCause(Throwable t, boolean forLog) { // Find all causes for this exception ArrayList<Throwable> causes = new ArrayList<Throwable>(); while (null != t) { causes.add(t); t = t.getCause(); } Collections.reverse(causes); // Work backwards through the causes to find the original // (hopefully most informative) detail string Iterator<Throwable> iter = causes.iterator(); String msg = null; while (iter.hasNext() && null == msg) { t = iter.next(); if (null != t.getMessage()) { // Detail string exists if (forLog) { // Always get class information as well msg = t.toString(); } else { msg = goodMessage(t); } } } // No detail found, use class information about root cause if (null == msg) { msg = (causes.get(0)).toString(); } return msg; }
From source file:com.taobao.top.convert.ConvertException.java
public ConvertException(Throwable cause) { super((cause == null ? null : cause.toString()), cause); }
From source file:com.xwtec.xwserver.util.json.JSONException.java
public JSONException(Throwable cause) { super((cause == null ? null : cause.toString()), cause); }