I just read this question, and a solution states that:
The fact that you don't know you got the NO_DATA_FOUND exception suggests that you have made one of the biggest errors PL/SQL developers ever make:
EXCEPTION -- Never do this in real code!!! WHEN OTHERS THEN NULL; END;
Could you explain me what is the error in this statement and what would you do to avoid doing that...
The problem is, that you are catching all exceptions, and then ignoring them. You'll never know when something went wrong.
There's nothing wrong with this snippet of code if you don't want the pl/sql block's exception to propagate any further for example. If you do it on purpose, it's not bad code or a mistake. That's the catch all in pl/sql. And there might be situations in code where you have nested BEGIN/EXCEPTION/END blocks and one might not want the transaction to fail just if a particular cross section of code fails. You can't state it's bad coding if you do it intentionally for whatever reason/requirement.
BEGIN
--something important here
--something even more important here
BEGIN
--something secondary goes here but not important enough to stop the process or
--log a message about it either
--maybe send an informative email to the support group or
--insert a log message when debugging the process or
--the list could go on and on here
EXCEPTION
--I don't care if this block fails, absorbing all errors regardless of type
WHEN OTHERS THEN NULL;
END;
-- something super important here, must happen
EXCEPTION
WHEN NO_DATA_FOUND THEN
-- do something useful for this exception
WHEN OTHERS THEN
-- do something by default if we don't expect this error
END;
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