Go Back   Wiki NewForum | Latest Entertainment News > Career Forum & Tips > Tech Forum & Tutorial > Oracle Database, SQL, Application, Programming


PL/SQL coding


Reply
Views: 1014  
Thread Tools Rate Thread Display Modes
  #1  
Old 05-26-2009, 03:25 AM
bholus7
Guest
 
Posts: n/a
Default PL/SQL coding

PL/SQL coding

1. Don't code Exception handlers unless you have a clear and compelling reason to do so. Unless there is a specific problem you are trapping, how can you ever guess what problem might occur? By leaving out the exception code and by following my no blank lines rule, the line number returned with the exception error points to the exact place the error occurred.



2. Don't raise your own exceptions in your procedures. My reasons-- they break the rules of structured programming. When you RAISE , it is just a disguised GOTO statement, which forces processing immediately to jump to the end of the procedure.



To handle a user-created exception, you have to write special code in three places in your procedure: you have to declare it (Pragma exception init...), you have to raise it (GOTO the end), and you have to handle it (Exception when...). It is so much easier and clearer to take care of a special condition in-line in your code, especially for someone else trying to read your code.



To pass back an error condition to a calling procedure, use a parameter -- something like Return_Code. Then the calling procedure can test the Return_Code value immediately after the call, making all the code easier to follow. If you use an exception in the caller, it isn't immediately clear to the next person reading your code that the sub procedure can raise such an error. It just confuses the process.

Reply With Quote
Reply

New topics in Oracle Database, SQL, Application, Programming


Thread Tools
Display Modes Rate This Thread
Rate This Thread:



Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
WikiNewForum)