As I'm sure you all know Java enforces a very strict pattern for error handling whereby any exception must be handled through either a try catch block or by declaring a method with the throws keyword. (I might add I really like the way its done)
Having said that; what I am struggling with is deciding on what the correct approach is to handling errors in various methods. Coming from a C#/VB.NET background I have previously always strictly adhered to handling errors (In everything but the most specific circumstances) at the bottommost of the stack, however I am not convinced that this is the best approach in Java.
Could anyone provide any input regarding this? What is considered best practice? How does one decide if they should infact throw an exception outside the method or handle it internally (Obviously some cases are obvious but allot aren't)?
On a per-method basis, I ask myself:
It's a trite answer, but catch the exception where you can actually do something with it to recover. Different exceptions will mean you may handle exceptions at different levels in the architecture.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With