List of usage examples for java.lang StackTraceElement getLineNumber
public int getLineNumber()
From source file:org.nuessler.junit.util.rule.FailureLogger.java
private String formatMessage(Description description, StackTraceElement element, Throwable t) { return String.format("%s in %s#%s, line %d: %s", t.getClass().getCanonicalName(), description.getTestClass(), description.getMethodName(), element.getLineNumber(), defaultString(t.getMessage(), "<no message>")); }
From source file:com.krawler.portal.util.ByteArrayMaker.java
private void _getInfo(Throwable t) { _initSize = buf.length;/* w w w . j av a 2 s . c o m*/ StackTraceElement[] elements = t.getStackTrace(); if (elements.length > 1) { StackTraceElement el = elements[1]; _caller = el.getClassName() + StringPool.PERIOD + el.getMethodName() + StringPool.COLON + el.getLineNumber(); } }
From source file:org.gradle.api.GradleScriptException.java
/** * Returns the line in the script where this exception occurred, if known. * * @return The line number, or null if not known. */// www. ja v a 2 s .c o m public Integer getLineNumber() { if (lineNumber != null) return lineNumber; // wasn't explicitly set, so search for the line number Integer foundLineNumber = null; String scriptFileName = scriptSource.getFileName(); for (Throwable currentException = this; currentException != null; currentException = currentException .getCause()) { for (StackTraceElement element : currentException.getStackTrace()) { if (scriptFileName.equals(element.getFileName()) && element.getLineNumber() >= 0) { foundLineNumber = element.getLineNumber(); break; } } } return foundLineNumber; }
From source file:gumga.framework.application.GumgaLoggerService.java
public String createLogLine(String msg, int level) { StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[level]; String line = sdf.format(new Date()) + " " + stackTraceElement.getClassName() + " " + stackTraceElement.getMethodName() + " " + stackTraceElement.getLineNumber() + " " + msg + "\n"; return line;/* w w w .j av a 2 s . co m*/ }
From source file:io.gumga.application.GumgaLoggerService.java
/** * * @param msg mensagem do log/* w w w .j av a 2 s. c om*/ * @param level index da execption do StrackTrace * @return dados do log */ public String createLogLine(String msg, int level) { StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[level]; String line = sdf.format(new Date()) + " " + stackTraceElement.getClassName() + " " + stackTraceElement.getMethodName() + " " + stackTraceElement.getLineNumber() + " " + msg + "\n"; return line; }
From source file:com.chiorichan.factory.ScriptTraceElement.java
public ScriptTraceElement(ScriptingContext context, StackTraceElement ste) { this.context = context; fileName = ste.getFileName();//from www . j a v a2s .c o m methodName = ste.getMethodName(); className = ste.getClassName(); lineNum = ste.getLineNumber(); colNum = -1; }
From source file:es.bsc.servicess.ide.Logger.java
private String printInvocationInfo(StackTraceElement invoker) { return "[" + invoker.getClassName() + "." + invoker.getMethodName() + "(" + invoker.getFileName() + ":" + invoker.getLineNumber() + ")]"; }
From source file:it.smartcommunitylab.aac.controller.BasicProfileController.java
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(Exception.class) @ResponseBody//from w w w .j a v a2s .c o m ErrorInfo handleBadRequest(HttpServletRequest req, Exception ex) { StackTraceElement ste = ex.getStackTrace()[0]; return new ErrorInfo(req.getRequestURL().toString(), ex.getClass().getTypeName(), ste.getClassName(), ste.getLineNumber()); }
From source file:cn.bran.play.JapidTemplateBase.java
@Override protected void handleException(RuntimeException e) { if (Play.mode == Mode.PROD) throw e;/*from w w w. j a v a 2 s. c o m*/ // find the latest japidviews exception StackTraceElement[] stackTrace = e.getStackTrace(); for (StackTraceElement ele : stackTrace) { String className = ele.getClassName(); if (className.startsWith("japidviews")) { int lineNumber = ele.getLineNumber(); // TODO: should really remove the Play reference. Shall we jump to the file system for the source? ApplicationClass applicationClass = Play.classes.getApplicationClass(className); if (applicationClass != null) { // let's get the line of problem String jsrc = applicationClass.javaSource; String[] splitSrc = jsrc.split("\n"); String line = splitSrc[lineNumber - 1]; // can we have a line marker? int lineMarker = line.lastIndexOf("// line "); if (lineMarker > 0) { int oriLineNumber = Integer.parseInt(line.substring(lineMarker + 8).trim()); StackTraceElement[] newStack = new StackTraceElement[stackTrace.length + 1]; newStack[0] = new StackTraceElement(sourceTemplate, "", sourceTemplate, oriLineNumber); System.arraycopy(stackTrace, 0, newStack, 1, stackTrace.length); e.setStackTrace(newStack); File file = new File("app/" + sourceTemplate); // JapidPlayTemplate jpt = new JapidPlayTemplate(); jpt.name = sourceTemplate; try { jpt.source = FileUtils.readFileToString(file); } catch (IOException e1) { e1.printStackTrace(); } throw new TemplateExecutionException(jpt, oriLineNumber, e.getMessage(), e); } } } } throw e; }
From source file:edu.cornell.mannlib.vitro.webapp.utils.developer.loggers.StackTraceUtility.java
public String format(boolean requested) { StringBuilder sb = new StringBuilder(); if (requested) { for (StackTraceElement ste : stackTrace) { sb.append(String.format(" %s.%s(%s:%d) \n", ste.getClassName(), ste.getMethodName(), ste.getFileName(), ste.getLineNumber())); }/*from w ww .j a v a 2 s. c o m*/ sb.append(" ...\n"); } return sb.toString(); }