List of usage examples for java.lang Exception getStackTrace
public StackTraceElement[] getStackTrace()
From source file:com.bah.applefox.main.plugins.pageranking.PageRank.java
/** * This method controls everything necessary to calculate page rank and * store it to a file/*from w w w .ja v a 2s.c om*/ * * @param args * - the string values to pass in * @param iterations * - the number of iterations to run * @param urlSplit * - the size of the split for all page rank tables * @return - whether or not the page rank was successfully calculated */ public static boolean createPageRank(String[] args, int iterations, String urlSplit) { try { AccumuloUtils.setSplitSize(urlSplit); ToolRunner.run(new CountURLs(), args); ToolRunner.run(new InitializePRTables(), args); for (int i = 0; i < iterations; i++) { Instance inst = new ZooKeeperInstance(args[0], args[1]); Connector conn = inst.getConnector(args[2], args[3].getBytes()); AccumuloUtils.connectBatchWrite(args[13] + "New"); ToolRunner.run(new MRPageRanking(), args); ToolRunner.run(new DampenTable(), args); conn.tableOperations().delete(args[13] + "Old"); conn.tableOperations().rename(args[13] + "New", args[13] + "Old"); } if (!PRtoFile.writeToFile(args)) { return false; } } catch (Exception e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } return false; } return true; }
From source file:jp.techie.achicoco.framework.util.LogUtil.java
/** * ??/* w w w . j a va2 s . c o m*/ * * @param className ?? * @return */ protected static int getLineNumber(String className) { try { throw new Exception(); } catch (Exception e) { StackTraceElement[] stackTraceElements = e.getStackTrace(); for (int i = 0; i < stackTraceElements.length; i++) { StackTraceElement element = stackTraceElements[i]; if (element != null && className.equals(element.getClassName())) { return element.getLineNumber(); } } } return 0; }
From source file:org.accada.reader.rprm.core.msg.MessageLayerConfiguration.java
/** * Singleton implementation of properties file accessor. * /* ww w . ja v a2s .c o m*/ * @return properties instance */ private static XMLConfiguration getProperties(final String propFile, final String defaultPropFile) { if (configuration == null) { // properties configuration = new XMLConfiguration(); try { // load resource from where this class is located Exception ex = new Exception(); StackTraceElement[] sTrace = ex.getStackTrace(); String className = sTrace[0].getClassName(); Class c = Class.forName(className); URL fileurl = ResourceLocator.getURL(propFile, defaultPropFile, c); configuration.load(fileurl); } catch (ConfigurationException e) { log.error("Could not find properties file: " + propFile); } catch (ClassNotFoundException cnfe) { log.error("Could not find properties file: " + propFile); } } return configuration; }
From source file:uy.edu.ort.fachada.FachadaOperaciones.java
public static void listarTrazas() { String url = ManejoPropiedades.obtenerInstancia().obtenerPropiedad("restService") + "resttrace/all.htm"; RestTemplate restTemplate1 = new RestTemplate(); restTemplate1.getMessageConverters().add(new StringHttpMessageConverter()); restTemplate1.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); Trace[] trazas = null;/* w w w . ja v a2 s. com*/ try { trazas = restTemplate1.getForObject(url, Trace[].class); } catch (Exception e) { System.out.println(e.getStackTrace().toString()); } System.out.println("\tFecha \t\tDescripcion"); for (Trace t : trazas) { String fechaString = new SimpleDateFormat("dd-MM-yyyy").format(t.getFecha()); System.out.println("\t" + fechaString + "\t\t" + t.getDescripcion()); } }
From source file:com.martinwunderlich.nlp.arg.aifdb.AIFdbArgumentMapFactory.java
public static List<AIFdbArgumentMap> buildArgumentMapListFromNodesetJsonFiles(String nodesetPath) { FileFilter fileFilter = new WildcardFileFilter("nodeset*.json"); File sourceDir = new File(nodesetPath); if (sourceDir == null || !sourceDir.isDirectory() || !sourceDir.exists()) throw new IllegalArgumentException("Invalid nodeset path provided for argument factory: " + nodesetPath + " is not a directory or does not exist."); File[] jsonFiles = sourceDir.listFiles(fileFilter); List<AIFdbArgumentMap> argMaps = new ArrayList<>(); for (File jsonFile : jsonFiles) { try {/* www. j a v a 2s . c o m*/ AIFdbArgumentMap map = buildFromJsonFile(jsonFile.getAbsolutePath()); argMaps.add(map); } catch (Exception ex) { System.out.println("Error while trying to build argumentation map from file " + jsonFile); System.out.println("Details: " + ex.getMessage()); System.out.println(ex.getStackTrace().toString()); } } System.out.println("Building list of argumentation maps...DONE"); System.out.println("Found " + argMaps.size() + " argumentation maps."); return argMaps; }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.java
static String getFilteredStackTrace(String filter) { Exception e = new Exception(); StackTraceElement[] stackTrace = e.getStackTrace(); StringBuilder sb = new StringBuilder(); for (StackTraceElement element : stackTrace) { if (element.getClassName().contains(filter)) { sb.append(element.toString()).append("\n"); }// w ww .ja v a 2 s . com } return sb.toString(); }
From source file:Main.java
/** * Pass an exception to get back the stack trace * @param pException//from w w w .j av a 2 s . c o m * @return stackTrace */ public static String getStackTrace(Exception pException) { if (pException != null) { final StringBuilder strBuilder = new StringBuilder("Cause of error: "); strBuilder.append(pException.getMessage()); strBuilder.append("\n"); strBuilder.append(pException.toString()); strBuilder.append("\n"); final StackTraceElement[] elementArray = pException.getStackTrace(); for (final StackTraceElement element : elementArray) { strBuilder.append(element.toString()); strBuilder.append("\n"); } return strBuilder.toString(); } else { return null; } }
From source file:com.github.mavogel.ilias.printer.VelocityOutputPrinter.java
/** * Prints the header, content and output to the given print stream with the default template from the classpath. * * @param outputType the desired output type. @see {@link OutputType} * @param contextMap the context for velocity * @throws Exception in case of a error, so the caller can handle it *//*w w w. j a v a 2 s . c om*/ private static void printWithDefaultTemplate(final OutputType outputType, final Map<String, Object> contextMap) throws Exception { VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); ve.init(); Writer writer = null; final String templateName = outputType.getDefaultTemplateLocation(); try { VelocityContext context = new VelocityContext(); contextMap.forEach((k, v) -> context.put(k, v)); Template template = ve.getTemplate(templateName, "UTF-8"); writer = new BufferedWriter(createFileWriter(outputType, templateName)); template.merge(context, writer); writer.flush(); } catch (ResourceNotFoundException rnfe) { LOG.error("Couldn't find the template with name '" + templateName + "'"); throw new Exception(rnfe.getMessage()); } catch (ParseErrorException pee) { LOG.error("Syntax error: problem parsing the template ' " + templateName + "': " + pee.getMessage()); throw new Exception(pee.getMessage()); } catch (MethodInvocationException mie) { LOG.error( "An invoked method on the template '" + templateName + "' threw an error: " + mie.getMessage()); throw new Exception(mie.getMessage()); } catch (Exception e) { LOG.error("Error: " + e.getMessage()); LOG.error("Cause: " + e.getCause()); Arrays.stream(e.getStackTrace()).forEach(LOG::error); throw e; } finally { if (writer != null) writer.close(); } }
From source file:edu.brown.utils.ClassUtil.java
/** * Return the stack trace for the location that calls this method. * @return// ww w.j a v a2 s . c o m */ public static String[] getStackTrace() { String ret[] = null; try { throw new Exception(); } catch (Exception ex) { StackTraceElement stack[] = ex.getStackTrace(); ret = new String[stack.length - 1]; for (int i = 1; i < stack.length; i++) { ret[i - 1] = stack[i].toString(); } // FOR } return (ret); }
From source file:com.antsdb.saltedfish.util.UberUtil.java
public static String getThisClassName() { Exception x = new Exception(); StackTraceElement[] stack = x.getStackTrace(); if (stack != null) { if (stack.length >= 2) { return stack[1].getClassName(); }//from ww w . j a v a 2 s.c o m } return ""; }