08.01.2015 Views

phsjhxx

phsjhxx

phsjhxx

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

48. Never assign predefined exception names to user defined exceptions.<br />

[CodeXpert 3010]<br />

Reason: This is error-prone because your local declaration overrides the global<br />

declaration. While it is technically possible to use the same names, it<br />

causes confusion for others needing to read and maintain this code.<br />

Additionally, you will need to be very careful to use the prefix<br />

"STANDARD" in front of any reference that needs to use Oracle’s default<br />

exception behavior.<br />

49. Avoid use of WHEN OTHERS clause in an exception section without any other<br />

specific handlers. (CodeXpert)<br />

[CodeXpert 3001]<br />

Reason: There isn't necessarily anything wrong with using WHEN OTHERS, but it<br />

can cause you to "lose" error information unless your handler code is<br />

relatively sophisticated. Generally, you should use WHEN OTHERS to grab<br />

any and every error only after you have thought about your executable<br />

section and decided that you are not able to trap any specific exceptions. If<br />

you know, on the other hand, that a certain exception might be raised,<br />

include a handler for that error. By declaring two different exception<br />

handlers, the code more clearly states what we expect to have happen and<br />

how we want to handle the errors. That makes it easier to maintain and<br />

enhance. We also avoid hard-coding error numbers in checks against<br />

SQLCODE<br />

Example:<br />

--Bad<br />

EXCEPTION<br />

WHEN OTHERS<br />

THEN<br />

IF SQLCODE = -1<br />

THEN<br />

update_instead (...);<br />

ELSE<br />

err.log;<br />

RAISE;<br />

END IF;<br />

--Good<br />

EXCEPTION<br />

WHEN DUP_VAL_ON_INDEX<br />

THEN<br />

update_instead (...);<br />

WHEN OTHERS<br />

THEN<br />

err.log;<br />

RAISE;<br />

PL/SQL Coding Guidelines 35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!