Hi, all.
I notice that sometimes the stack trace shows a line number and sometimes it doesn't. (Sometimes it only shows the method name which generated the exception.
For example, while running, my code generated a NullPointerException, and the stack trace showed no line number where the exception occurred:
-------------------------------------------------------
java.lang.NullPointerException
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java:73)
at java.lang.NullPointerException.<init>(NullPointerException.java:60)
at java.math.BigDecimal.matchScale(BigDecimal.java:1787)
at java.math.BigDecimal.add(BigDecimal.java:496)
at com.republic.externalinterface.billingExport.TFGBillingExport.groupStmtItemPrintDOListBySortKey(TFGBillingExport.java)
at com.republic.externalinterface.billingExport.TFGBillingExport.transformStatementLevelElement(TFGBillingExport.java)
----------------------------------------------------------------------
I added a try-catch block around the code in the method, caught and re-threw NullPointerException, and now the printStackTrace shows the exact line number:
------------------------------------------------------------------------
java.lang.NullPointerException
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at com.republic.externalinterface.billingExport.TFGBillingExport.groupStmtItemPrintDOListBySortKey(TFGBillingExport.java:545)
at com.republic.externalinterface.billingExport.TFGBillingExport.transformStatementLevelElement(TFGBillingExport.java)
-----------------------------------------------------------------------
I'm trying to tweak my code so that it ALWAYS shows a line number in the stack trace, since obviously, that's useful post-mortem information.
Anyone know what the general
java rule is for this? I don't think I've evere seen it written anywhere before.
Ben Ethridge
SCJP 1.4