Friday, December 16, 2016

Do Comments Throw Off Error Backtrace? No!


Just received this feedback on an Oracle Magazine article:
I’ve just started using DBMS_UTILITY.FORMAT_ERROR_BACKTRACE and it’s a great utility when the code contains no comments, but unless I’m missing something it’s not terribly useful with regard to pinpointing the exact line number when the code contains comments.
Now, I must confess that I am tempted to respond with such questions along these lines:
Did you try it out? That's the best way to learn!
But I am always looking for another reason to post on my blog and add to the LiveSQL repository. So that's what I am doing! :-)

The answer is quite straightforward:

Comments do not interfere with "pinpointing the exact line number" on which the error was raised.

But I bet you want proof, so let's get down to business.

I create a procedure with comments and a RAISE statement:

CREATE OR REPLACE PROCEDURE comments_throw_off_line# 
IS 
/* 
Here's my header 
 
Blah blah blah 
*/ 
BEGIN 
   DBMS_OUTPUT.put_line ('wow!'); 
   /* 
   And here's another comment because I really love 
   to fill my code with meaningless comments! 
   */ 
   RAISE PROGRAM_ERROR; /* This is line 14 */ 
EXCEPTION 
   WHEN OTHERS 
   THEN 
      DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_backtrace); 
END;

I run the procedure and see this output:

BEGIN 
   comments_throw_off_line#; 
END;

wow!
ORA-06512: at "COMMENTS_THROW_OFF_LINE#", line 14

So, there's your answer.

Next question? :-)

No comments:

Post a Comment