Stack trace as String

后端 未结 7 1283
梦谈多话
梦谈多话 2020-12-23 20:18

How do I get full exception message in Java?

I am creating a Java Application. If there is a runtime exception, a JDialog with a JTextArea

相关标签:
7条回答
  • 2020-12-23 21:01

    if you are not using any logger(Log4j or oracle logger api) then you can use the below statement to print the full exception message

    try{
           // statement which you want to monitor 
    
    }catch(Exception e){
        e.printStackTrace()
        // OR System.err.println(e.getStackTrace());
        // OR System.err.println(e);
        // OR System.err.println(e.getMessage());
        // OR System.err.println(e.getCause());
    }
    

    if you are using the Logger API then use the below statement

    try{
    
             // statement which you want to monitor 
    
    }catch(Exception e){
      log.error(e,e); 
    }
    
    0 讨论(0)
提交回复
热议问题