List of usage examples for java.lang StackTraceElement getLineNumber
public int getLineNumber()
From source file:controllers.GWT2Controller.java
public static void invoke(String module, String service) throws Exception { // find the module GWT2Module mod = GWT2Plugin.getModule(module, service); if (mod == null) notFound("module not found !"); if (mod.service == null) throw new NullArgumentException("module.service is null"); // create service instance GWT2Service gwtService;//from w ww .j a v a 2s . c o m try { gwtService = (GWT2Service) mod.service.newInstance(); if (!GWT2Service.class.isAssignableFrom(mod.service)) throw new Exception("module.service is not GWT2Service instance"); } catch (Exception e) { StackTraceElement element = PlayException.getInterestingStrackTraceElement(e); if (element != null) { throw new JavaExecutionException(Play.classes.getApplicationClass(element.getClassName()), element.getLineNumber(), e); } throw new JavaExecutionException(e); } // decode rpc request RPCRequest rpcRequest = RPC.decodeRequest(IO.readContentAsString(request.body), gwtService.getClass(), gwtService); // response load String responseload = null; // check GWT2ServiceAsync GWT2ServiceAsync gwt2AsyncCall = mod.service.getAnnotation(GWT2ServiceAsync.class); if (gwt2AsyncCall != null && gwt2AsyncCall.value()) { // async invokation responseload = invokeAsync(gwtService, rpcRequest); } else { // synced invokation // bt service can use GWT2Chain to do async job responseload = invoke(gwtService, rpcRequest); } renderText(responseload); }
From source file:griffon.util.GriffonUtil.java
public static void printSanitizedStackTrace(Throwable t, PrintWriter p) { t = sanitize(t);/* w w w . j a va 2 s . c o m*/ StackTraceElement[] trace = t.getStackTrace(); for (int i = 0; i < trace.length; i++) { StackTraceElement stackTraceElement = trace[i]; p.println("at " + stackTraceElement.getClassName() + "(" + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber() + ")"); } }
From source file:Main.java
private static String getFunctionName() { StackTraceElement[] sts = Thread.currentThread().getStackTrace(); if (sts == null) { return null; }// w w w .j a v a 2s . com for (StackTraceElement st : sts) { if (st.isNativeMethod()) { continue; } if (st.getClassName().equals(Thread.class.getName())) { continue; } if (st.getFileName().equals("LogUtils.java")) { continue; } return "[" + Thread.currentThread().getName() + "(" + Thread.currentThread().getId() + "): " + st.getFileName() + ":" + st.getLineNumber() + "]"; } return null; }
From source file:org.kei.android.phone.cellhistory.CellHistoryApp.java
@SuppressWarnings("unchecked") public static void addLog(final Context c, final Object msg) { final CellHistoryApp ctx = CellHistoryApp.getApp(c); ctx.lock();//from ww w . j a va 2s. c o m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); if (prefs.getBoolean(Preferences.PREFS_KEY_LOG_ENABLE, Preferences.PREFS_DEFAULT_LOG_ENABLE)) { String head = new SimpleDateFormat("yyyyMMdd [hhmmssa]: \n", Locale.US).format(new Date()); try { throw new Exception(); } catch (Exception e) { StackTraceElement ste = e.getStackTrace()[1]; String name = ste.getClassName(); int n = -1; if ((n = name.lastIndexOf('.')) != -1) name = name.substring(n + 1); head += name + "->" + ste.getMethodName() + "(" + ste.getLineNumber() + ")\n"; } ctx.getLogBuffer().add(head + msg); } ctx.unlock(); }
From source file:controllers.GWT2Controller.java
/** * Invoke a Service /* w ww . j ava 2 s . c o m*/ * * This way GWT2Service is allowed to use GWT2Chain * * @param mod * @return * @throws Exception */ private static String invoke(GWT2Service service, RPCRequest rpcRequest) throws Exception { String responseload = null; try { // Get GWt2Invoker GWT2Invoker invoker = new GWT2Invoker(service, request, response, session, rpcRequest); // run boolean run = true; Object result = null; Object chainResult = null; boolean firstcall = true; GWT2ChainRuntime chain = null; while (run) { try { if (firstcall) { firstcall = false; // call service result = invoker.invoke(); // get a result stop request run = false; } else if (chain != null) { // call callback result = chain.getChain().chain(chainResult); // get a result stop request run = false; } else { // no callback to call stop process run = false; } } catch (GWT2ChainAsync casync) { // async chain call chain = casync; chainResult = chainAwait(chain); } catch (GWT2ChainSync csync) { chain = csync; chainResult = chainDo(chain); } catch (InvocationTargetException ite) { if (ite.getTargetException() instanceof GWT2ChainAsync) { // async chain call chain = (GWT2ChainAsync) ite.getTargetException(); chainResult = chainAwait(chain); } else if (ite.getTargetException() instanceof GWT2ChainSync) { chain = (GWT2ChainSync) ite.getTargetException(); chainResult = chainDo(chain); } else throw ite; } } // encode result responseload = RPC.encodeResponseForSuccess(rpcRequest.getMethod(), result, rpcRequest.getSerializationPolicy(), AbstractSerializationStream.DEFAULT_FLAGS); return responseload; } catch (Exception ex) { if (ex instanceof PlayException) // Rethrow the enclosed exception throw (PlayException) ex; // if not gwt rpc rethrow if (!isGWT()) throw ex; try { // else encode error responseload = RPC.encodeResponseForFailure(rpcRequest.getMethod(), ex, rpcRequest.getSerializationPolicy(), AbstractSerializationStream.DEFAULT_FLAGS); } catch (SerializationException e) { StackTraceElement element = PlayException.getInterestingStrackTraceElement(e); if (element != null) { throw new JavaExecutionException(Play.classes.getApplicationClass(element.getClassName()), element.getLineNumber(), e); } throw new JavaExecutionException(e); } } return responseload; }
From source file:de.domjos.schooltools.helper.Helper.java
public static void printException(Context context, Throwable ex) { StringBuilder message = new StringBuilder(ex.getMessage() + "\n" + ex.toString()); for (StackTraceElement element : ex.getStackTrace()) { message.append(element.getFileName()).append(":").append(element.getClassName()).append(":") .append(element.getMethodName()).append(":").append(element.getLineNumber()); }//from w w w . ja v a2 s . c om Log.e("Exception", message.toString(), ex); Log4JHelper.getLogger(context.getPackageName()).error("Exception", ex); Helper.createToast(context, ex.getLocalizedMessage(), false); }
From source file:com.googlecode.flyway.commandline.Main.java
/** * Output class, method and line number infos of first stack trace element * of the given {@link Throwable} using {@link Log#error(Object)}. * * @param t {@link Throwable} to log/*from w w w .j a v a2 s . c o m*/ */ private static void outputFirstStackTraceElement(Throwable t) { StackTraceElement firstStackTraceElement = t.getStackTrace()[0]; LOG.error("Occured in " + firstStackTraceElement.getClassName() + "." + firstStackTraceElement.getMethodName() + "() at line " + firstStackTraceElement.getLineNumber()); }
From source file:com.snicesoft.basekit.LogKit.java
private static String generateTag(StackTraceElement caller) { // String tag = "%s.%s(L:%d)"; String tag = "%s.%s(" + caller.getFileName() + ":%d)"; String callerClazzName = caller.getClassName(); callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1); tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber()); tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag; return tag;/*w w w .ja va2 s. c o m*/ }
From source file:com.cloud.utils.StringUtils.java
public static String getExceptionStackInfo(final Throwable e) { final StringBuffer sb = new StringBuffer(); sb.append(e.toString()).append("\n"); final StackTraceElement[] elemnents = e.getStackTrace(); for (final StackTraceElement element : elemnents) { sb.append(element.getClassName()).append("."); sb.append(element.getMethodName()).append("("); sb.append(element.getFileName()).append(":"); sb.append(element.getLineNumber()).append(")"); sb.append("\n"); }/*from ww w . j av a 2 s .com*/ return sb.toString(); }
From source file:org.evosuite.regression.RegressionExceptionHelper.java
/** * Get signature based on the root cause from the stack trace * (uses: location of the error triggering line from CUT) * @param CUT the class to expect the exception to be thrown from * @return signature string//from ww w. j ava 2 s.c o m */ public static String getExceptionSignature(Throwable throwable, String CUT) { String signature = throwable.getClass().getSimpleName(); StackTraceElement[] stackTrace = throwable.getStackTrace(); for (StackTraceElement el : stackTrace) { String elClass = el.getClassName(); if (!Objects.equals(elClass, CUT)) { continue; } String method = el.getMethodName(); int line = el.getLineNumber(); signature += ":" + method + "-" + line; break; } return signature; }