OnError Event (AProgram, ADriver, ASystem)

Occurs when an error occurred in the application.

Syntax

Object.OnError()

The OnError event syntax has the following parts:

 

Name

Type

Description

Object

AProgram, ADriver, ASystem

Module object

Comments

The OnError events apply to the Driver and System modules. ATEasy will call first the module that the error occurred in, then continue and call the other module events Program, System Drivers (if exist in your project) in reverse order, and last the System (if exist in your project). If the event procedure does not contain code then ATEasy will not call the event.

The OnError events can call the Abort, Retry  or Ignore statement to handle the error. If the OnError returns normally (using the Return statement), the default error handling message box will be called displaying a message box with an error description and location and the Abort, Ignore, Retry or Pause buttons for the user to select.

The OnError events is called by ATEasy as result of the code run-time error or when the Error statement is used in the code. Run-time error can occurred as result of instrument not responding, divide by 0 and more.

The following list shows the order of OnError events combined with default output (see ModuleEvents.prj example for more information). The error ocuured in the example is inside driver1:

 

   * Driver1.OnError

   * Program.OnError

   * Driver2.OnError

   * System.OnError

Run-time error #-1 : '' found in 'Driver1.OnInitTest' in line 2

 

...Application aborted.

   * Program.OnAbort

Use the OnError events to handle and trap errors on a global module. You can also use the Try-Catch statement to handle errors locally.  The code inside the OnError event can perform cleanup and to turn off instrument power before the application is exited or the offending problem is ignored or retried. You can also redirect ATEasy to ignore and not to exit by running another program, task or test using the Run, Task and Test statements.

Example

The following is an example of one way to use the OnEndProgram event:

System.OnEndProgram()

{

! ... system cleanup code ...

print "System has cleaned up after the end of program "; Program.Name

}

Example

The following is an example of one way to use the OnError event:

prg1.OnError()

{

! ... program cleanup code ...

print "Program "; Program.Name; " has cleaned up after error # "; GetErrorNum()

}

Applies to

AProgram, ADriver, ASystem

See Also

Abort Statement, Error Statement,Exit Statement,  Ignore Statement, Pause Statement, Retry Statement, OnAbort, OnEnd, Trace Statement, Try Statement, Error Events, About Module Events, GetErrorNum, GetErrorMsg, GetErrorModule