Monica Shiralkar wrote:C# has only the concept of checked exceptions.
because the compiler reminds me I have to take care of them.
Thanks. Yes that is a reason.
lazy programmers don't care to handle them properly and just declare a throws clause on all their method signatures.
Stephan van Hulst wrote:It's okay to let some exceptions bubble up the call stack until they reach the appropriate method to handle them, but many programmers just let exceptions bubble all the way up, or even worse, handle the exception too soon by just logging a message (or sometimes not even that!)
Use the “surround with try‑catch” feature on your IDE.
Monica Shiralkar wrote:. . . why does Java not come up with a feature where . . . whatever coding you do that implicitly comes under a try catch.
Monica Shiralkar wrote:I am thinking that why does Java not come up with a feature where you do not need to explicitly provide try catch and whatever coding you do that implicitly comes under a try catch.
Junilu Lacar wrote:I prefer the general approach used by Spring to handle checked vs unchecked: wrap low-level checked exceptions with unchecked exceptions and let the developers decide where they want to handle it. If nobody handles it, the exception just keeps getting propagated back up the application stack where it either stops the application or gets handled by a generic catch-all exception handler.
Sometimes the answer is,
What am I going to do if this exception is thrown?
Sometimes you cannot work out what to do about an exception at all. Sometimes, as often with null pointer exceptions, it is necessary to prevent them rather than handling them, and that might even require alterations to the code.
Pass it on to the calling method.