Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it okay to handle Runtime exceptions?

Tags:

java

exception

It's generally a good practice to not handle runtime exceptions.

I have this scenario :

  /**boolean returns false if the method execution fails,
  so that an error can be shown to user*/ 
boolean saveData()
 {
    try
    {
         //Some database calls that throw only Runtime exceptions
     }
     catch(Exception e)
     {
         //Log the exception and return false
         return false;
     }
     return true;

 }

So from the Servlet calling it will get a boolean value. If it's false, we show a message 'Save Not sucessful'. Is this okay or is there a better way of doing it ?

like image 643
Vinoth Kumar C M Avatar asked Jan 28 '26 02:01

Vinoth Kumar C M


1 Answers

Is it okay to handle Runtime exceptions?

As long as you can do something intelligent at that point, yes. This 'never catch run-time exceptions' is pure nonsense. You'll probably want to log them and do other things, as well.

like image 82
Andrew Thompson Avatar answered Jan 29 '26 15:01

Andrew Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!