Exception tracking
December 20th, 2002
Free Java tip of the day: If you're hunting down an Exception somewhere, get the stack trace! Some people like the "concise" System.out.println(exc.getMessage());, which isn't of much help. I've just seen some people that I thought knew a bit of Java, looking at an error message ("NullPointerException"), and at some code, trying to guess where the error occurred. tomK's rule #412: a NullPointerException always occurs on another place than you think. You'll end up spending several hours trying to fix an NPE that wasn't there in the first place. The first thing you should do when you have to fix an Exception like this, is to get the stack trace, recompile, and re-trigger the bug. To make life even easier, include the stack trace when writing the code (in a file! exc.printStackTrace() is useless when running on a server).

Leave a Reply