Chapter Contents


SAS Component Language: Reference

Using the Program Halt Handler

The program halt handler is designed to handle unexpected run-time errors. The programHalt class contains methods that are called when certain run-time exceptions occur. By overriding these methods, you can specify whether an application should halt immediately or continue executing. You can control how exceptions are handled.

In the following example, the _onGeneric method creates a list named MSGS, inserts information about the location where the application failed into the list, and displays the list with the MESSAGEBOX function. You can use this code to create your own program halt handler.

class myHalt extends
   _onGeneric:method / (STATE='O');
      dcl list msgs=makelist();
      rc = insertc(msgs, "SCL program failed at ", 1);
      rc = insertc(msgs, "Entry=" || entry, 2);
      rc = insertc(msgs, "Line=" || putn(lineNumber, "3.0"), 3);
      if (keywordType = 'function') then
         rc = insertc(msgs, "Function=" || keyword, 4);
         rc = insertc(msgs, "Method=" || keyword, 4);

      rc = messageBox(msgs);

      /* continue execution */
      stopExecution = 'No';

Note:   Entry, lineNumber, keyword, and keywordType are all object attributes that are defined in the class sashelp.classes.programHalt.class.  [cautionend]

The _onGeneric method traps any error messages that are generated by SCL and saves them in the MSGS list. Developers can use this list to identify and fix potential problems in their code.

The programHalt handler must be declared at the beginning of your application. For example:

dcl myHalt obj = _new_ myHalt();

Your program can instantiate multiple programHalt handlers, or your program may instantiate only one handler, but then call a second program that instantiates its own handler. The last programHalt handler that is instantiated is the current programHalt handler. Only the current programHalt handler is active at any one time.

SCL uses a stack to keep track of programHalt handlers. Each time a programHalt handler is instantiated, the new instance is pushed onto the stack. The handler on the top of the stack is always the active handler. Before a program terminates it must terminate (using the _term method) its programHalt handler. For example:

Terminating a programHalt handler pops it from the stack, and makes the next programHalt handler on the stack the active handler.

For example, if your program instantiates the programHalt handler, and then calls another SCL program, the second program may also instantiate a programHalt handler. The second programHalt handler becomes the current programHalt handler. Before the second program ends, it must terminate the second programHalt handler. The first programHalt handler then becomes the current programHalt handler. If the second programHalt handler is not terminated, it will remain active even after the program that instantiated it has terminated.

Chapter Contents



Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.