G-5020: Never handle unnamed exceptions using the error number.
Critical
Maintainability
Reason
When literals are used for error numbers the reader needs the error message manual to unterstand what is going on. Commenting the code or using constants is an option, but it is better to use named exceptions instead, because it ensures a certain level of consistency which makes maintenance easier.
Example (bad)
1 2 3 4 5 6 7 8 9 10 11 12 13 | declare k_no_data_found constant integer := -1; begin my_package.some_processing(); -- some code which raises an exception exception when too_many_rows then my_package.some_further_processing(); when others then if sqlcode = k_no_data_found then null; end if; end; / |
Example (good)
1 2 3 4 5 6 7 8 9 | begin my_package.some_processing(); -- some code which raises an exception exception when too_many_rows then my_package.some_further_processing(); when no_data_found then null; -- handle no_data_found end; / |