Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>No, I don't think that this would at all be "useful".</p> <p>Instead, you should watch out not to throw NPEs in the first place. Checking your values before you use them (<code>null</code> validation) and the likes. This should happen <em>before</em> you call a library method and <em>after</em> you get back a result (iff the API specifies that the method may return <code>null</code>. Of course, sometimes it will do so anyways, but then that's a bug).</p> <p>If you think that NPEs should carry this information for debugging, think again. That's what debuggers are good for. An exception is simply there to inform you that something has gone wrong. Remember that unchecked exceptions occur at runtime - and have to be generated there. In order for the Exception to know which <em>variable</em> contained <code>null</code>, the <strong>byte</strong> <strong>code</strong> would have to know about variable names. You don't want to bloat your byte code with stuff like this. The class name is contained in every logging output I recieve from my programs. That's what logging is good for.</p> <p>Java already eases the debugging process a lot by giving you the line number and full stack trace. C programs fail with <code>Segmentation fault</code>. You have to use <code>strace</code> or a debugger in order to even get so much information.</p> <p>Note that <code>javac</code> <em>does</em> include a compile time option to include source file information at compile time, but this is intended to be used by a debugger, <strong>not</strong> the random Exceptions that get thrown. Quoting Sun's <code>javac</code> man page:</p> <pre> -g Generate all debugging information, including local variables. By default, only line number and source file information is generated. -g:none Do not generate any debugging information. -g:{keyword list} Generate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are: source<br/> Source file debugging information lines Line number debugging information vars Local variable debugging information </pre> <p>Long story short: use a debugger.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload