Chapter Contents

Previous

Next
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
   sashelp.classes.programHalt.class;
   _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);
      else
         rc = insertc(msgs, "Method=" || keyword, 4);

      /* At this point, you may want to      */
      /* call the TRACEBACK routine and dump */
      /* attributes from the class (using    */
      /* the _getAttributes method).         */

      rc = messageBox(msgs);

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

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

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();


Chapter Contents

Previous

Next

Top of Page

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