Re: Retrieving line number of error with err_get
Posted in 1993
->From: hlt@napcc-hp (Harold Trammel) ->Subject: Retrieving line number of error with err_get ->Date: Tue, 25 May 1993 15:20:01 GMT ->Reply-To: hlt@napcc-hp (Harold Trammel) ->Organization: University of Illinois at Urbana -> ->When the WHENEVER ERROR STOP statement is used in an Informix-4gl program, ->the program aborts and the startlog() function writes the routine name, the ->line number (well, sort of B-) ), the error code, and corresponding error ->message out to the errorlog file. -> ->I would like to have similar behavior with the WHENEVER ERROR CALL (or even ->CONTINUE) statements. I have an error_handler function that uses err_get() ->to read the error messages for the error codes and I put them in the file ->with errorlog(). -> ->How can I get to the routine and line number? I need to have the ->application used by regular users and record the problems that arrise. My ->error_handler just records what the error was, not the approximate location ->of the error. -> ->Short of writing error free code from the onset, is there any way I can get ->the routine name and line numbers for my use? -> ->Thanks! ->-- ->--------------------------------------------------------------------- ->Harold L. Trammel h-trammel@uiuc.edu | ->National Animal Poison Control Center | ->College of Veterinary Medicine | PRACTICE RANDOM KINDNESS ->Univ. of Illinois Urbana-Champaign | AND SENSELESS ACTS OF BEAUTY ->===================================================================== -> I can't help you with line numbers. However, two simple and comparatively low cost (but not very elegant) approaches to getting function names follow: Method A: 1. Add a CHAR(n) variable func_name to your GLOBALS file. 2. As you enter each FUNCTION, LET func_name = "this_name". 3. After every function CALL, put another LET statement to reset the func_name to the current FUNCTION. [This is the main drawback to this method.] 4. In your WHENEVER ERROR CALL function, print the func_name in your message. Method B: 1. Add an ARRAY OF CHAR(n) variable func_name to your GLOBALS file, along with a SMALLINT variable func_indx. 2. Remember to initialize func_indx to 0, along with the rest of your program initializations. 3. On entry to each FUNCTION, LET func_indx = func_indx + 1 LET func_name[func_indx] = "this_name" 4. Before returning from each FUNCTION, LET func_indx = func_indx - 1 5. In your WHENEVER ERROR CALL function, print the func_name[func_indx] in your message. Optionally, print the entire call stack. I think method B is better. DISADVANTAGE: You need to guess a good max size for your func_name array. ADVANTAGES: You have the *complete* call stack available to you if you want it. This method also trashes your code less than method A; you have two new lines after each FUNCTION entry and one before each RETURN, instead of two on entry and one after every CALL. Assuming your FUNCTIONs are moderate in size, the lack of line numbers should not be too much of a problem. The error number normally indicates what type of SQL operation failed. This should localize things, unless you do a long series of INSERTs in one function, or something similar. Regards, Alan +------------------------------+---------------------------------------+ | R. Alan Popiel | Internet: alan@den.mmc.com | | Martin Marietta, LSC | ( Please note: My opinions do not ) | | P.O. Box 179, M/S 5422 | ( represent official Martin policy. ) | | Denver, Colorado 80201-0179 | Voice: 303-977-9998 | +------------------------------+---------------------------------------+