简体   繁体   中英

Why doesn't the stack trace get printed?

While trying to print the stack trace in my browser window, I fail. Following is the sample of the exception block.

try {
    // Add Code Here
} catch(Exception exc) { exc.printStackTrace();}

I am using google app engine as my server. What could be the reason the stack trace is not printing ?

Because there is no Exception to catch:

try {
    // Add Code Here
}

You will only print a stack trace an Exception is thrown within the try block like this:

try {
    throw new RuntimeException();
}

The method in question is implemented like this:

public void printStackTrace() {
    printStackTrace(System.err);
}

If your container/IDE/framework redirects the stream then you will not observe it at the expected location, see also System.setErr(...); . And of course, I expect you to have checked that your code really throws an Exception (if an Error then it will not be caught by your clause).

You will need to change the default error output stream. Since you are most probably coding a servlet , you could change to :

exc.printStackTrace(response.getWriter());

This will print the exception trace into the browser window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM