-3

Help with this please Using "when others then Null;" is 01 recommended best practice?

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
  • Have a look at this - http://stackoverflow.com/questions/1438405/what-is-bad-in-when-others-then-null-in-pl-sql – Dhanuka Jun 29 '15 at 14:16

1 Answers1

2

Definitely not recommeneded when used alone, but when you club this with other set of known exceptions it is acceptable.

For eg: In the event of capturing all known exceptions you can certainly use WHEN OTHERS clause, but avoid using NULL instead have something meaningful and try to add this in future. But if you are very sure to ignore some known exceptions where there is no action, then you can very well use this. But this is seldom seen in professional codes

DECLARE
   <declarations section>
BEGIN
   <executable command(s)>
EXCEPTION
   <exception handling goes here >
   WHEN exception1 THEN 
       exception1-handling-statements 
   WHEN exception2  THEN 
      exception2-handling-statements 
   WHEN exception3 THEN 
      exception3-handling-statements
   ........
   WHEN others THEN
      exception3-handling-statements
END;
Srini V
  • 11,045
  • 14
  • 66
  • 89
  • "But if you are very sure to ignore some known exceptions where there is no action, then you can very well use this" <---- as long as you add a comment explaining why you're using it! – Boneist Jun 29 '15 at 15:03