Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should NullRefs ever be caught?

I recently made the statement to a colleague that:

NullReferenceExceptions should never be explicitly caught

I used the word never.... hmmm. I've never seen a appropriate use case myself for catching them but I wanted to check if anyone else has?

Never is such a strong word after all.....

like image 528
Quibblesome Avatar asked Dec 07 '22 08:12

Quibblesome


1 Answers

It depends on why; see Eric Lippert's blog entry. If they are "boneheaded exceptions", then no - just fix the calling code. In the rare case that they are "vexing exceptions" (i.e. the code you are calling has traps that are hard to avoid), then I guess you'd have to.

like image 200
Marc Gravell Avatar answered Dec 20 '22 05:12

Marc Gravell