Re: Java & XML
On Mon, 18 Jan 2010 22:23:39 -0800 (PST), aix five <aix530@gmail.com>
wrote, quoted or indirectly quoted someone who said :
Can anyone help me how to handle JAVA NullPointerException?
Is it possible to continue to run in "<>" as shown below?
Or I need to assign a new value if String A is null?
Please advice. Thanks.
String AA = getXMLInfo(XXX, "YY");
String A = myDate.convert(AA, inDateFormat, outDateFormat);
String BB = getXMLInfo(VVV, "UU");
String B = myDate.convert(BB, inDateFormat, outDateFormat);
catch (NullPointerException e)
{
System.out.println("main: Oops, null exception caught");
<continue to run and assign
A=B, C=D;>
}
Your code gives Java programmers indigestion because you are ignoring
the naming conventions A and BB are normally class names, not variable
names. a and bb are variable names. See
http://mindprod.com/jgloss/codingconventions.html
you need
try { ... } catch ( NullPointerException e ) { recovery... }
Triggering an exception is a quite slow operation. So normally you
would handle it like this with explicit checks:
String a = (value != null) ? value : "huh?";
--
Roedy Green Canadian Mind Products
http://mindprod.com
Responsible Development is the style of development I aspire to now. It can be summarized by answering the question, ?How would I develop if it were my money?? I?m amazed how many theoretical arguments evaporate when faced with this question.
~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming .