ErrHandler Help

Demo Programs

Contents | Bottom

The demo application, errhdemo.exe, is for testing and illustrating the general features of ErrHandler.  This simple demo can be run under the Visual FoxPro Development System or as a stand-alone VFP runtime application.  It consists of a small "wrapper" function and dialog for running VFP command lines with error handling and diagnostics.  Try running the demo to get a quick idea of ErrHandler's capabilities.  By studying the program design, you can see how to use ErrHandler in your own applications.

Sample Error Message Screens

The above snapshot of a VFP window shows the demo dialog right after entering an invalid command line ("jajaja") and clicking on the Run button.  The resulting error message is displayed in a WAIT window at the top.  In the Command window you can see the command line that was used to invoke the dialog.

The MESSAGEBOX( ) function is used for longer messages, in order to avoid exceeding VFP's 254 character limit on the length of WAIT WINDOW messages.  In those cases, the error message would look similar to this:

A diagnostic mode of displaying messages is also supported, as shown below: 

The diagnostic message dialog provides user-selectable debugging, tracing, and output options.  It also supports an Abort command, for abnormally terminating a program or sub-application as cleanly as possible.  (The Ignore and Retry commands are automatically enabled only in certain error contexts, controlled programmatically.)

How to Start the Demo

The simplest way to test the ErrHandler demo application is to issue the following VFP command line:

errhdemo( )

The wrapper function launches a modal form that can run any VFP command line.  Try it out, supplying an example of an invalid command.  Note that when you exit from this dialog, the PUBLIC memory variable m.erh will point to an ErrHCustom class object containing detailed error information, even though the form no longer exists.

The errhdemo( ) application supports 2 optional arguments, an action code and a command line.  For example, if you issue the following command:

? errhdemo('run', 'phony command line')

this will execute the (invalid) command line "phony command line" in non-interactive mode, causing an error message to be displayed.  (Errhdemo.scx is invoked, but you don't see the form, because it's deliberately hidden in this mode.)  The error message disappears if you move the mouse, because it was issued with the NOWAIT option, since this is a non-interactive invocation.  The function return value is a logical success flag value, with extended error information returned in the ErrHandler object pointed to by m.erh, as before.  So if you ran the previous command, the result displayed to the VFP main window would be .F., and if you then type this command:

? m.erh.ehp_vfperrno

the value 16 is displayed, because this is the VFP error number for "Unrecognized command verb".  Additional detailed VFP error information can be obtained from the other properties of the ErrHandler object.

The Action Code Argument

The following action codes (defined in include file errhandl.h) are supported as the first argument to errhdemo( ):

Prompt
(The default action) prompts the user with a modal dialog.  The form stays active and foremost until you close it, at which point the wrapper function returns its success flag result, and extended error information persists in the object pointed to by m.erh.
PromptN
Prompts the user with a modeless (Non-modal) dialog form, i.e. you don't have to close the form to activate another window.  The function return value is not useful in this case, because errhdemo( ) returns immediately while the form is still active and awaiting further interaction with the user.  But the error information for the dialog remains accessible in the usual ErrHandler properties.
Run
Runs a command line non-interactively (modal invocation).  You won't see the dialog in this mode, and there is no pause on errors.  (If an error message is displayed, the NOWAIT option is used.)  The function return value indicates success or failure, and extended error information persists in the ErrHandler object pointed to by m.erh, although the dialog no longer exists upon return.
RunN
Runs a command line non-interactively (non-modal invocation).  This is the modeless flavor of the preceding Run action.  The modal/modeless distinction may seem confusing, since the dialog is hidden and non-interactive in either case.  But in this case, the (hidden) dialog continues to exist after being called to run the given command line.  The wrapper function returns a success flag that reflects the success or failure of running the command line.  If a subsequent invocation of erhandl() is made with the RunN action, the previous instance of the form is reused, saving the expense of re-instantiating it.

Obtaining Extended Error Information

A basic success/failure indicator comes from the wrapper function's return value, i.e. as a logical True/False result.  When the result is .F., indicating that there was an error, you can also get additional detailed error information in the following standardized way.  For all of the supported actions, the demo is configured to return extended error information attached to a public memory variable, m.erh, in an ErrHandler object that is separate from the form itself.  (This feature is governed by a flexible option called "target indirection", controlled by property settings.)  In addition, the modeless cases allow you to get to the extended error information by directly referencing the form's own error-handling properties (prefixed by ehp_ ).

Demo Components

Aside from the general-purpose ErrHandler classes and core functions, the demo consists of the following programs:

Since these programs exist purely for demo purposes, they are not required for incorporating ErrHandler into your own applications.


ErrHandler Forum

Discussion

 Top | Unframe 


Copyright © 2000 - 2002, SpaceTime Systems