List of usage examples for java.lang Exception getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:json_to_xml_1.java
public static void main(String args[]) { System.out.print("json_to_xml_1 workflow Copyright (C) 2016 Stephan Kreutzer\n" + "This program comes with ABSOLUTELY NO WARRANTY.\n" + "This is free software, and you are welcome to redistribute it\n" + "under certain conditions. See the GNU Affero General Public License 3\n" + "or any later version for details. Also, see the source code repository\n" + "https://github.com/publishing-systems/digital_publishing_workflow_tools/ and\n" + "the project website http://www.publishing-systems.org.\n\n"); json_to_xml_1 converter = json_to_xml_1.getInstance(); converter.getInfoMessages().clear(); try {/*from w w w . j a v a2 s . c o m*/ converter.execute(args); } catch (ProgramTerminationException ex) { converter.handleTermination(ex); } if (converter.resultInfoFile != null) { try { BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(converter.resultInfoFile), "UTF-8")); writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); writer.write( "<!-- This file was created by json_to_xml_1, which is free software licensed under the GNU Affero General Public License 3 or any later version (see https://github.com/publishing-systems/digital_publishing_workflow_tools/ and http://www.publishing-systems.org). -->\n"); writer.write("<json-to-xml-1-result-information>\n"); if (converter.getInfoMessages().size() <= 0) { writer.write(" <success/>\n"); } else { writer.write(" <success>\n"); writer.write(" <info-messages>\n"); for (int i = 0, max = converter.getInfoMessages().size(); i < max; i++) { InfoMessage infoMessage = converter.getInfoMessages().get(i); writer.write(" <info-message number=\"" + i + "\">\n"); writer.write(" <timestamp>" + infoMessage.getTimestamp() + "</timestamp>\n"); String infoMessageText = infoMessage.getMessage(); String infoMessageId = infoMessage.getId(); String infoMessageBundle = infoMessage.getBundle(); Object[] infoMessageArguments = infoMessage.getArguments(); if (infoMessageBundle != null) { // Ampersand needs to be the first, otherwise it would double-encode // other entities. infoMessageBundle = infoMessageBundle.replaceAll("&", "&"); infoMessageBundle = infoMessageBundle.replaceAll("<", "<"); infoMessageBundle = infoMessageBundle.replaceAll(">", ">"); writer.write(" <id-bundle>" + infoMessageBundle + "</id-bundle>\n"); } if (infoMessageId != null) { // Ampersand needs to be the first, otherwise it would double-encode // other entities. infoMessageId = infoMessageId.replaceAll("&", "&"); infoMessageId = infoMessageId.replaceAll("<", "<"); infoMessageId = infoMessageId.replaceAll(">", ">"); writer.write(" <id>" + infoMessageId + "</id>\n"); } if (infoMessageText != null) { // Ampersand needs to be the first, otherwise it would double-encode // other entities. infoMessageText = infoMessageText.replaceAll("&", "&"); infoMessageText = infoMessageText.replaceAll("<", "<"); infoMessageText = infoMessageText.replaceAll(">", ">"); writer.write(" <message>" + infoMessageText + "</message>\n"); } if (infoMessageArguments != null) { writer.write(" <arguments>\n"); int argumentCount = infoMessageArguments.length; for (int j = 0; j < argumentCount; j++) { if (infoMessageArguments[j] == null) { writer.write(" <argument number=\"" + j + "\">\n"); writer.write(" <class></class>\n"); writer.write(" <value>null</value>\n"); writer.write(" </argument>\n"); continue; } String className = infoMessageArguments[j].getClass().getName(); // Ampersand needs to be the first, otherwise it would double-encode // other entities. className = className.replaceAll("&", "&"); className = className.replaceAll("<", "<"); className = className.replaceAll(">", ">"); String value = infoMessageArguments[j].toString(); // Ampersand needs to be the first, otherwise it would double-encode // other entities. value = value.replaceAll("&", "&"); value = value.replaceAll("<", "<"); value = value.replaceAll(">", ">"); writer.write(" <argument number=\"" + j + "\">\n"); writer.write(" <class>" + className + "</class>\n"); writer.write(" <value>" + value + "</value>\n"); writer.write(" </argument>\n"); } writer.write(" </arguments>\n"); } Exception exception = infoMessage.getException(); if (exception != null) { writer.write(" <exception>\n"); String className = exception.getClass().getName(); // Ampersand needs to be the first, otherwise it would double-encode // other entities. className = className.replaceAll("&", "&"); className = className.replaceAll("<", "<"); className = className.replaceAll(">", ">"); writer.write(" <class>" + className + "</class>\n"); StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); exception.printStackTrace(printWriter); String stackTrace = stringWriter.toString(); // Ampersand needs to be the first, otherwise it would double-encode // other entities. stackTrace = stackTrace.replaceAll("&", "&"); stackTrace = stackTrace.replaceAll("<", "<"); stackTrace = stackTrace.replaceAll(">", ">"); writer.write(" <stack-trace>" + stackTrace + "</stack-trace>\n"); writer.write(" </exception>\n"); } writer.write(" </info-message>\n"); } writer.write(" </info-messages>\n"); writer.write(" </success>\n"); } writer.write("</json-to-xml-1-result-information>\n"); writer.flush(); writer.close(); } catch (FileNotFoundException ex) { ex.printStackTrace(); System.exit(-1); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); System.exit(-1); } catch (IOException ex) { ex.printStackTrace(); System.exit(-1); } } converter.getInfoMessages().clear(); converter.resultInfoFile = null; }
From source file:Main.java
public static String getExceptionString(Exception e) { return ".\nType: " + e.getClass().getSimpleName() + "\nCause: " + e.getCause() + "\nMessage: " + e.getMessage();//from ww w . j ava 2 s. c o m }
From source file:Main.java
public static void failExit(final Activity activity, final String task, final String msg, final Object o) { if (o instanceof Exception) { Exception e = (Exception) o; String emsg = e.getClass().getName() + ": " + e.getMessage(); String m = task + " " + msg + ": " + emsg; Log.e(task, m);//from ww w .ja v a 2 s.c om alert(activity, m, "ok", true); } else { alert(activity, "Hop Fail Exit: " + o.toString(), "ok", true); } }
From source file:Main.java
public static Object invoke(Object receiver, Object defaultValue, Method method, Object... args) { if (method == null) return defaultValue; try {/*from w ww. j av a2 s. co m*/ return method.invoke(receiver, args); } catch (Exception e) { Log.e(TAG, "Exception in invoke: " + e.getClass().getSimpleName()); } return defaultValue; }
From source file:com.kaidad.utilities.MBTilesBase64Converter.java
private static Connection connectToDb(String dbName) { Connection c = null;/* w w w . j av a 2 s .c o m*/ try { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:" + dbName); c.setAutoCommit(false); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); System.exit(0); } System.out.println("Opened database [" + dbName + "] successfully"); return c; }
From source file:LogToFile.java
private static HttpResponse ExecuteRequest(HttpUriRequest request) { try {// www . ja va 2 s . c o m HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(request); return response; } catch (Exception e) { Log.e("", e.getClass().getName() + "\n" + e.getMessage()); } return null; }
From source file:com.kalessil.phpStorm.phpInspectionsEA.utils.analytics.AnalyticsUtil.java
public static void registerPluginEvent(@NotNull EASettings source, @NotNull String action, @NotNull String eventValue) { new Thread() { public void run() { /* See https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event */ final StringBuilder payload = new StringBuilder(); payload.append("v=1") // Version. .append("&tid=").append(COLLECTOR_ID) // Tracking ID / Property ID. .append("&cid=").append(source.getUuid()) // Anonymous Client ID. .append("&t=event") // Event hit type .append("&ec=plugin") // Event Category. Required. .append("&ea=").append(action) // Event Action. Required. .append("&el=").append(source.getVersion()) // Event label - current version .append("&ev=").append(eventValue.replaceAll("[^\\d]", "")) // Event value - oldest version as int ;//from ww w.j a va 2 s . c o m try { Request.Post(COLLECTOR_URL).bodyByteArray(payload.toString().getBytes()).connectTimeout(3000) .execute(); lastError = null; } catch (Exception failed) { lastError = failed.getClass().getName() + " - " + failed.getMessage(); } } }.start(); }
From source file:LogToFile.java
public static void LogToFile(String log) { try {/*w w w. j a va 2 s .co m*/ HashMap<String, String> params = new HashMap<String, String>(); params.put(LOG_TO_FILE_LOG_PARAMETER, log); HttpPost request = Post( String.format("%s:%d%s", LOG_TO_FILE_ADDRESS, LOG_TO_FILE_PORT, LOG_TO_FILE_URL), params, null); HttpResponse response = ExecuteRequest(request); response.getEntity().consumeContent(); } catch (Exception e) { Log.e("", e.getClass().getName() + "\n" + e.getMessage()); } }
From source file:Main.java
public static void logErrorStackTrace(Object source, Exception e, String msg) { String tag = source.getClass().getSimpleName(); Log.e(tag, msg + ": " + e.getClass().getSimpleName() + ":"); Log.e(tag, Log.getStackTraceString(e)); }
From source file:LogToFile.java
private static HttpPost Post(String url, HashMap<String, String> params, HashMap<String, ArrayList<String>> arrayParams) { try {/*from w w w . java2 s. co m*/ if (!url.endsWith("/")) url += "/"; List<NameValuePair> params_list = null; if (params != null) { params_list = new LinkedList<NameValuePair>(); for (Entry<String, String> entry : params.entrySet()) params_list.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } if (arrayParams != null) { if (params_list == null) params_list = new LinkedList<NameValuePair>(); for (Entry<String, ArrayList<String>> entry : arrayParams.entrySet()) for (String value : entry.getValue()) params_list.add(new BasicNameValuePair(entry.getKey(), value)); } HttpPost request = new HttpPost(url); if (params != null) request.setEntity(new UrlEncodedFormEntity(params_list, "utf-8")); return request; } catch (Exception e) { Log.e("", e.getClass().getName() + "\n" + e.getMessage()); } return null; }