1

my servlet is throwing a NullPointerException. I want to show the full stack call trace so that I can find out the line number the exception is being thrown at.

How can I do that? I have already used fillInStackTrace(). it is not printing the line number.

Fredrik Mörk
  • 155,851
  • 29
  • 291
  • 343
prometheuspk
  • 3,754
  • 11
  • 43
  • 58
  • 2
    AFAIK the stack trace should be filled in automatically in runtime exceptions, you shouldn't need to do anything specific about it. Could you post the actual code to display the exception stack trace? – Péter Török Apr 12 '11 at 09:33
  • do you want to show it in the server console\logs or as part of your response to the client/browser? – anirvan Apr 12 '11 at 09:33
  • as part of response. should appear on the page. – prometheuspk Apr 12 '11 at 10:05
  • If the problem is that there are no stacktrace lines at all (which seem to be the case), then see here for the reason+solution in this stackoverflow question: https://stackoverflow.com/a/3010106/197141 – arberg Apr 26 '23 at 12:57

3 Answers3

6

Have you tried using e.printStackTrace()?

aseychell
  • 1,794
  • 17
  • 35
1

Assuming you are getting stacktraces without line numbers (which is what the last sentence of the Question seems to be saying), then the problem is that your code has been compiled without debug information. You will need to recompile it ...

  • If you are building using Maven, you should get debug information by default. Check the maven.compile.debug and maven.compile.debuglevel properties in the java plugin configs; see http://maven.apache.org/maven-1.x/plugins/java/properties.html

  • If you are building using Ant, make sure that the <javac> task has debug='true' and check the debuglevel attribute.

  • If you are building by running javac directory, you should get line numbers by default. Check the -g options against the javac manual page.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

Try Thread.dumpStack()

Umesh K
  • 13,436
  • 25
  • 87
  • 129