onerror
STATEMENTS
The onerror statement can be used to catch all errors that are not trapped by if error or try statements.
Parameters
This statement has one parameter:
statements – is a text string that contains one or more Panorama statements to be executed when an error occurs. Notice that this is not the name of a procedure, but the actual statements themselves (as a string of text). This is similar to the execute statement. Once an error has occurred, these statements will run. Within these statements you can use the info(“error”) function to find out what the error was, if necessary.
Description
The onerror statement can be used to catch all errors that are not trapped by if error
or try statements. This has two benefits: 1) It allows the programmer to easily eliminate all error alert dialogs. This is very important for server applications because an alert dialog requires human intervention to get the server going again. 2) It makes it easy to build a log of errors.
When Panorama encounters an error, it checks to see if the next line is if error
. If not, it usually stops and displays an error message. However, if an onerror statement has been encountered, Panorama will not stop and will not display an error message. Instead, it will execute the statements specified as the parameter to the onerror statement.
The effect of the onerror statement ends when the main procedure stops running. In other words, onerror isn’t a permanent error handler – you must specify it for each procedure you wish to have error trapping. If you plan to use onerror, it is probably best to put it in the first line of any procedure that needs error trapping. If you are going to use the same statements with onerror in several different procedures, you may want to set up the statements in a variable in your .Initialize
procedure, then use that variable as the parameter to onerror.
It’s important to consider the possible environment that may exist when an error occurs. Depending on the flow of your main procedure, Panorama may not be in the same window or even in the same database. Your onerror program should generally not make any assumptions about what windows or databases will be active or available when the error occurs.
Here is an example of how onerror could be used in a CGI (web server) application. In this example, if there is an error, Panorama will return an error message to the web server and also log the error along with the date and time.
global cgiResult,errorLog
errorLog=errorLog // make sure errorLog exists
if error
errorLog="" // initialize errorLog
endif
onerror {cgiResult="Panorama Error: "+info("error") }+
{errorLog=sandwich("",errorLog,cr())+}+
{datepattern( today(),"DD/MM/YYYY ")+}+
{timepattern( now(),"hh:mm:ss")+}+
{info("error")}
// error logging is set up, now we can continue with our tasks
...
... rest of this procedure
Note that you should be very careful when setting up your onerror code. If your onerror code itself contains an error, that error will not be trapped and a message alert will appear. In that case, Panorama will display the original error message, plus a message indicating that there is a problem with the onerror code
See Also
- call -- allows a procedure to call a separate procedure within the current database as a subroutine.
- call( -- allows a procedure to be called as a subroutine within a formula and return a result.
- calledby( -- returns true if this function is in code called by the specified database, the specified procedure, or both.
- callerslocalvariablevalue( -- allows a subroutine to access a local variable in the procedure that called it.
- callingdatabase( -- returns the name of the database that called this procedure as a subroutine, if any.
- callingprocedure( -- returns the name of the procedure that called this procedure as a subroutine, if any.
- callwithin -- allows a procedure to call a mini-procedure within a separate procedure within the current database as a subroutine.
- callwithin( -- allows a "mini-procedure" to be called as a subroutine within a formula and return a result.
- callwithindatabase( -- returns true if the current procedure was called by another procedure in the same database, false if it was called by a procedure in another database.
- case -- allows multiple decisions to be chained together (also see the elseif statement).
- catch -- works with try and endcatch to trap errors in a sequence of statements.
- catcherror( -- evaluates an expression, but suppresses any error generated by that expression.
- console -- sends a message to the console log.
- Custom Database Initialization -- using an .Initialize procedure to automatically run custom code when a database opens.
- debug -- stops the current program, allowing you to examine variables or single step.
- defaultcase -- works together with the case statement to specify statements that will be executed if none of the *case* statements are true.
- disableabort -- prevents loops from being stopped early by pressing SHIFT-COMMAND-ESCAPE or by exceeding the maximum allowed loop time.
- else -- works together with the if statement to specify statements that will be executed for both the *true* and *false* cases.
- elseif -- allows multiple if decisions to be chained together.
- enableabort -- allows the SHIFT-COMMAND-ESCAPE key sequence to stop an endless loop.
- endcase -- marks the end of statements controlled by a previoius case statement.
- endcatch -- works with try and catch to trap errors in a sequence of statements.
- endif -- marks the end of statements controlled by a previoius if statement.
- endloop -- is used at the end of a loop.
- Error Handling -- Techniques for trapping runtime errors instead of letting them abort the program.
- Error Wizard -- Advanced dialog for displaying program errors.
- error( -- returns an error with the specified message.
- errortext( -- evaluates an expression, but returns only the error message generated (if any).
- execute -- allows a procedure to call a sequence of statements within the current procedure as a "mini-subroutine".
- execute( -- allows a formula to execute a sequence of statements and return a result.
- executeasap -- executes the specified code at the first possible opportunity, non-atomically.
- executecatcherrors -- is the same as the execute statement, except for the fact that if an error occurs while running, it can be trapped by an if error statement immediately following the executecatcherrors statement.
- executelocal -- is the same as the execute statement, but it shares local variables with the procedure that called it.
- farcall -- allows a procedure to call a separate procedure within a different database as a subroutine.
- farcallwithin -- allows a procedure to call a mini-procedure within a separate procedure in a different database as a subroutine.
- for -- is used at the beginning of a loop that loops a fixed number of times.
- goto -- allows a procedure to arbitrarily jump from one spot to another
within the procedure.
- if -- decides what code to execute next.
- info("callerslocalvariables") -- returns a list of local variables defined in the procedure that called the current procedure.
- info("error") -- returns the most recent error message.
- info("errorparameter") -- returns the parameter that caused a runtime error.
- info("errorstack") -- returns the contents of the procedure stack after an error.
- info("errorstatement") -- returns the name of the statement that Panorama was trying to run at the time an error occurred.
- info("labels") -- lists the labels in the current procedure.
- info("procedurestack") -- returns the contents of Panorama's procedure call stack.
- loop -- is used at the beginning of a loop.
- looparray -- is used at the beginning of a loop that loops over the elements of an array.
- loopdataarray -- is used at the beginning of a loop that loops over the elements of a data array.
- loopindex -- allows a procedure to determine how many times a loop has been repeated.
- loopwhile -- is used at the beginning of a loop.
- noimplicitassignment -- does nothing, and is only retained for compatibility with earlier versions.
- nop -- does nothing (**n**o **op**eration).
- nslog -- sends a message to the console log.
- onfailedresume -- is used to setup a semi-graceful recovery if a resume statement fails because there was no pause statement.
- parameter( -- is used to transfer data between a main procedure and a subroutine.
- pause -- temporarily pauses a procedure.
- Preventing Endless Loops -- setting up a timeout limit to prevent endless loops.
- quit -- quits Panorama.
- repeatloopif -- decides whether to continue with a loop or to start over again from the top.
- resume -- resumes a procedure that has been temporarily halted with the pause statement.
- resumeaftertask -- resumes after a waitfortask statement.
- return -- ends a subroutine.
- returnerror -- passes an error back to the current subroutines calling procedure.
- setcallerslocal -- allows a subroutine to modify a local variable in the procedure that called it.
- seterror -- changes the error message returned by info("error").
- setparameter -- is used to transfer data from a subroutine back to the main
procedure that called it.
- setwaitinglocal -- assigns a value to a local variable in the parent procedure of an asynchronous task, allowing the asynchronouse code to pass a value back to the code that spawned it.
- shortcall -- allows a procedure to call a sequence of statements within the current procedure as a "mini-subroutine".
- stdout -- sends one or more characters to standard output.
- stop -- stops all running procedures immediately.
- stoploopif -- decides whether to continue with a loop or to exit the loop immediately.
- throwerror -- causes an immediate error.
- try -- works with catch and endcatch to trap errors in a sequence of statements.
- until -- is used at the end of a loop, and can control how many times the loop is executed.
- usecallerslocalvariables -- temporarily swaps out a subroutine's current local variables with the local variables of the procedure that called this subroutine. The statement can be used only in a subroutine, not in a calling procedure.
- usefunctioncallerslocalvariables -- temporarily swaps out a procedures current local variables with the local variables of the procedure that called this the call(, callwithin( or execute( function.
- usemylocalvariables -- reverses the action of the UseCallersLocalVariables statement, switching back to the current procedure's normal local variables.
- waitfortask -- temporarily pauses a procedure until the specified task is complete.
- while -- is used at the end of a loop, and can control how many times the loop is executed.
History
10.0 | Updated | Carried over from Panorama 6.0, but now if the onerror code itself has an error the message alert will display both the original error and the fact that there is an error in the onerror code. |