G-5040: Avoid use of WHEN OTHERS clause in an exception section without any other specific handlers.

Major

Reliability

Reason

There is not necessarily anything wrong with using WHEN OTHERS, but it can cause you to "lose" error information unless your handler code is relatively sophisticated. Generally, you should use WHEN OTHERS to grab any and every error only after you have thought about your executable section and decided that you are not able to trap any specific exceptions. If you know, on the other hand, that a certain exception might be raised, include a handler for that error. By declaring two different exception handlers, the code more clearly states what we expect to have happen and how we want to handle the errors. That makes it easier to maintain and enhance. We also avoid hard-coding error numbers in checks against SQLCODE.

Example (bad)

BEGIN
   my_package.some_processing();
EXCEPTION
   WHEN OTHERS THEN
      my_package.some_further_processing();
END;
/

Example (good)

BEGIN
   my_package.some_processing();
EXCEPTION
   WHEN DUP_VAL_ON_INDEX THEN
      my_package.some_further_processing();
END;
/