List of usage examples for java.lang Throwable printStackTrace
public void printStackTrace()
From source file:com.crushpaper.ThreadedSynchronousStreamReader.java
/** * Synchronously forks a child process capturing its standard out and err * into StringBuffers. Returns the child process's exit code or -1 if it is * not available. It creates threads for each stream because that is * required in Java to avoid the possibility of deadlock. *///w ww. j a v a2 s . c om public static int exec(StringBuffer output, StringBuffer error, String args[]) { try { String osName = System.getProperty("os.name"); if (osName.equals("Windows 95")) { String[] prefix = new String[2]; prefix[0] = "command.com"; prefix[1] = "/C"; args = ArrayUtils.addAll(prefix, args); } else if (osName.startsWith("Windows")) { String[] prefix = new String[2]; prefix[0] = "cmd.exe"; prefix[1] = "/C"; args = ArrayUtils.addAll(prefix, args); } Runtime runtime = Runtime.getRuntime(); Process childProcess = runtime.exec(args); ReaderThread errorReader = new ReaderThread(childProcess.getErrorStream(), output); ReaderThread outputReader = new ReaderThread(childProcess.getInputStream(), error); errorReader.start(); outputReader.start(); int exitValue = childProcess.waitFor(); return exitValue; } catch (Throwable t) { t.printStackTrace(); } return -1; }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromPath(String localpath, long allowedBmpMaxMemorySize) { try {//from w w w. j ava 2 s . c o m final Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(localpath, options); options.inSampleSize = calculateInSampleSize(options, allowedBmpMaxMemorySize); options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(localpath, options); } catch (Throwable err) { err.printStackTrace(); } return null; }
From source file:com.heliosdecompiler.helios.Helios.java
public static void displayError(Throwable t) { t.printStackTrace(); StringWriter writer = new StringWriter(); t.printStackTrace(new PrintWriter(writer)); JOptionPane.showMessageDialog(null, writer.toString(), t.getClass().getSimpleName(), JOptionPane.INFORMATION_MESSAGE); }
From source file:io.github.jeddict.collaborate.issues.ExceptionUtils.java
public static void printStackTrace(String errorMessage, final Throwable t, final ModelerFile file) { t.printStackTrace(); if (StringUtils.isBlank(errorMessage)) { errorMessage = t.getMessage();// ww w .j av a 2s . c o m if (StringUtils.isBlank(errorMessage)) { if (t.getCause() != null && StringUtils.isNotBlank(t.getCause().getMessage())) { errorMessage = t.getCause().getMessage(); } else if (t.getStackTrace().length > 0) { errorMessage = t.getStackTrace()[0].toString(); } } } final String message = errorMessage; LOG.log(Level.ALL, errorMessage, t); String content = file != null ? file.getContent() : ""; SwingUtilities.invokeLater(() -> { ExceptionReporterPanel exceptionReporterPanel = new ExceptionReporterPanel(message, t, content); exceptionReporterPanel.setVisible(true); }); }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromUrl(String urlpath, long allowedBmpMaxMemorySize) { String tmpDir = System.getProperty("java.io.tmpdir", "."); File saveFile = new File(tmpDir, UUID.randomUUID().toString()); if (saveFile.exists()) { saveFile.delete();// w ww. ja va2s . c o m } try { saveFile.createNewFile(); File ret = downloadFile(urlpath, saveFile); if (ret == null) {// fail. return null; } Bitmap bmp = decodeSampledBitmapFromPath(saveFile.getAbsolutePath(), allowedBmpMaxMemorySize); return bmp; } catch (Throwable err) { err.printStackTrace(); } finally { if (saveFile.exists()) { saveFile.delete();// true. } } return null; }
From source file:Main.java
private static InputStream getInputStreamFromUrl_V9(Context paramContext, String paramString) { if (confirmDownload(paramContext, paramString)) { try {//from www. j av a2 s.c o m URL localURL = new URL(paramString); HttpURLConnection localHttpURLConnection2 = (HttpURLConnection) localURL.openConnection(); localHttpURLConnection2.setRequestProperty("Accept-Charset", "UTF-8"); localHttpURLConnection2.setReadTimeout(30000); localHttpURLConnection2.setConnectTimeout(30000); localHttpURLConnection2.setRequestMethod("GET"); localHttpURLConnection2.setDoInput(true); localHttpURLConnection2.connect(); return localHttpURLConnection2.getInputStream(); } catch (Throwable localThrowable) { localThrowable.printStackTrace(); return null; } } else { return null; } }
From source file:Main.java
public static void copyInputStreamToFile(InputStream inputStream, File file) throws IOException { FileOutputStream fileOutputStream = null; FileChannel fileChannel = null; try {/*w w w . java2 s . c o m*/ fileOutputStream = new FileOutputStream(file); fileChannel = fileOutputStream.getChannel(); byte[] bArr = new byte[4096]; while (true) { int read = inputStream.read(bArr); if (read <= 0) { break; } fileChannel.write(ByteBuffer.wrap(bArr, SYSTEM_ROOT_STATE_DISABLE, read)); } } catch (Throwable throwable) { throwable.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (Exception e) { e.printStackTrace(); } } if (fileChannel != null) { try { fileChannel.close(); } catch (Exception e2) { e2.printStackTrace(); } } if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (Exception e22) { e22.printStackTrace(); } } } }
From source file:com.screenslicer.common.Log.java
public static void init(String loggerName, boolean allowFileLogging) { logger = Logger.getLogger(loggerName); if (allowFileLogging) { FileHandler fh = null;/*from w w w . ja va2 s . co m*/ try { fh = new FileHandler("../" + loggerName + ".log", 250000, 9, true); logger.addHandler(fh); String logLevel = System.getProperty("screenslicer-logging", "prod"); if (logLevel.equals("prod")) { logger.setLevel(Level.INFO); } else if (logLevel.equals("debug")) { logger.setLevel(Level.ALL); } SimpleFormatter formatter = new SimpleFormatter(); fh.setFormatter(formatter); } catch (Throwable t) { t.printStackTrace(); throw new RuntimeException(t); } } }
From source file:Main.java
public static String convertPhoneNumberTo8Format(String text) { try {/* w ww . j a v a2 s . c om*/ text = text.trim(); if (text.charAt(0) == '+') { text = text.substring(1); } if (text.charAt(0) == '7') { StringBuilder strBuilder = new StringBuilder(text); strBuilder.setCharAt(0, '8'); text = strBuilder.toString(); } BigInteger dummy = new BigInteger(text); if (text.charAt(0) != '8' || text.length() != 11) { throw new Exception(); } } catch (Throwable t) { text = ""; //LOGE("convertPhoneNumberTo8Format: " + t.getMessage()); t.printStackTrace(); } return text; }
From source file:Main.java
public static String validateAndFixUserPhoneNumber(String text) { try {//from w w w .j a v a 2 s .c o m text = text.trim(); if (text.charAt(0) == '+') { text = text.substring(1); } BigInteger dummy = new BigInteger(text); if (text.charAt(0) == '8') { StringBuilder strBuilder = new StringBuilder(text); strBuilder.setCharAt(0, '7'); text = strBuilder.toString(); } if (text.charAt(0) != '7' || text.length() != 11) { throw new Exception(); } text = "+" + text; } catch (Throwable t) { text = ""; //LOGE("validateAndFixUserPhoneNumber: " + t.getMessage()); t.printStackTrace(); } return text; }