ErrHandler Help |
Demo Programs |
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.
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.)
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 following action codes (defined in include file errhandl.h) are supported as the first argument to errhdemo( ):
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_ ).
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.