-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Martin,
The following example is patently false. Do not follow its example:
Martin Gainty wrote:
> the instant you execute code where a variable is NULL you will throw
> NullPointerException if you want robust code you are better off
> wrapping in try catch block as in
>
> try
> {
> if( in == null)
> System.out.println("This statement will never be executed ")
> + "as NullPointerException will be thrown");
> }
> catch(NullPointerException npe)
> {
> System.out.println("variable in has thrown NullPointerException "
> + "so something about that here");
> }
Referencing a NULL reference is not a problem. /De/-referencing a null
reference will give you an NPE. For example:
Integer i = null;
System.out.println(i); // Works
System.out.println(i.intValue()); // Throws NPE: i is null
Catching NullPointerException is a sign that the developer is too lazy
to check for NPEs pro-actively, and is the hallmark of poorly written code.
Do yourself a favor and check for things that are likely to be null
before you get an NPE. It will execute a whole lot faster, too ;)
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFWOZw9CaO5/Lv0PARAslcAJwJzq6DZnfj3wrSdXreUVOE8H9dsACfU/Ev
15/zmKHf2u/bOAundatCcXM=
=h85f
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: [email protected]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]