tags:

views:

209

answers:

1

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...

+3  A: 

The problem is, that you are catching all exceptions, and then ignoring them. You'll never know when something went wrong.

Matthew Watson
You mean that the bad practice here is not by using "When Others Then Null", but *only* using it, i.e. whitout catching any other exception before?
romaintaz
No, its bad to ever use it. at the VERY least, your when others clause should log the exception somewhere. but most likely you should log and raise the exception
Matthew Watson
@Matthew: I disagree. There are a number of perfectly valid scenarios where you would want to catch all exceptions and ignore them. Whether you log them or not is up to you. I do agree that 9 times out of ten you'd want to do some kind of logging but if I'm doing some kind of best-efforts code in a frequently used, low level API then I'd probably skip the overheads of logging.
darreljnz
@darreljnz: and then one day you'll be scratching your head over why something is failing, and have go adding debug code, or run through the debugger to find the place where its failing.There may be very limited cases, I would suspect its more like 999/1000 than 9/10 though.
Matthew Watson
Bottom line: if you don't care if the process fails, you don't therefore care if the process succeeds - so why waste resources doing it in the first place - delete the code entirely.
Jeffrey Kemp