Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, in Java’s parlance an Exception is a recoverable code path, Error is the kind that is not.

E.g. a network call failing due to some IOException can be easily retried, that’s a proper error handling.



How are you supposed to recover from IllegalArgumentException or NullPointerException?


Recoverable, as a technical term. You can catch an NPE and follow it with any kind of code you wish, it will be correctly “handled” by the VM. (The semantics of course depend on the exact specifics, but returning a server 500 error and not failing the process for example in a web server is completely valid).

You can try catching an OutOfMemory Error, but it is not guaranteed that your handling code can successfully run. Hence, non-recoverable.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: