java - check our package in stacktrace -


i have stack trace array below

stacktraceelement[] stacktrace = e.getstacktrace(); 

from stack trace below need first line of mypackage.

    org.apache.cxf.jaxrs.client.abstractclient.checkclientexception(abstractclient.java:522)     @ org.apache.cxf.jaxrs.client.clientproxyimpl.dochainedinvocation(clientproxyimpl.java:544)     @ org.apache.cxf.jaxrs.client.clientproxyimpl.invoke(clientproxyimpl.java:205)     @ $proxy94.run(unknown source)     @ com.mypackage.service.bankbridgeservicetest.test(bankbridgeservicetest.java:507) com.mypackage.service.bankbridgeservicetest.test(bankbridgeservicetest.java:102)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) 

i wrote code like

for(stacktraceelement stacktraceelement : stacktrace){         if(!stacktraceelement.isnativemethod())         {             system.out.println(stacktrace.tostring())             break;         }     } 

but not working. can me on this?.

use stacktraces[0].getclassname() , figure out package there.

example

public class stackerror {     public static void throwex() {         int x = 4 / 0;     }      public static void method2() {         throwex();     }      public static void main(string[] args) {         try {             method2();         } catch (exception e) {             e.printstacktrace();             stacktraceelement[] stacktraces = e.getstacktrace();             if(!stacktraces[0].isnativemethod())             system.out.println("class name :: "+stacktraces[0].getclassname());          }     } } 

output - class name :: content_management.school.service.stackerror

hope helps


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -