Microsoft KB Archive/95291

{|
 * width="100%"|

-

The information in this article applies to:


 * Microsoft Visual Basic Standard and Professional Editions for MS-DOS, version 1.0

-

SUMMARY
This article and the associated .OBJ file are available in the Software Library. The article describes how compiled programs can determine the module name and address offset where a trapped error occurred. This technique can be used in stand-alone compiled programs (BC option /O used) only.

MORE INFORMATION
The following file is available for download from the Microsoft Software Library:

"ERRADDR.EXE" For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base: "Q119591 How to Obtain Microsoft Support Files from Online Services" In a compiled program, if you use ON ERROR GOTO 0 in an error handler, Basic prints a message, such as the following:

Overflow in line 6 of module TEST at address 4D40:00B0

The offset (00B0 in this example) locates the ON ERROR GOTO 0 statement rather than the statement that caused the error. Therefore, if you use ON ERROR GOTO 0, and you want to locate the statement that caused an error based on the offset, you can use the technique described below. Alternatively, if you used line numbers in your program, you can locate the cause of the error by using the line number shown in the error message (6 in this example).

The module ERR.OBJ contains the procedure ErrAddress which obtains the module name and the address offset at which a trappable run-time error occurred. To use ErrAddress, follow these steps.

  Call ErrAddress from your error handler and print the module name and address offset returned.   DECLARE SUB ErrAddress (modname$, SEG segment%, SEG offset%) ON ERROR GOTO errorHandler ...  errorHandler: CALL ErrAddress(a$, segment%, offset%) PRINT &quot;error in &quot;; a$; &quot; line:&quot;; ERL; &quot;offset &quot;; HEX$(offset%)   Compile your modules using BC option /O and specify a listing file. For example, "BC /O /E TEST.BAS,,TEST.LST" The listing file shows the offset of each statement.  Link and run your program. When the error occurs, look up the offset printed by the error handler in the module's listing file. The error occurred in the code immediately previous to the address.

ErrAddress must be called directly from the error handler. It cannot be called from a subroutine or procedure that was called from the error handler. ErrAddress works with programs compiled with Visual Basic for MS-DOS only.

Example Code
The following example demonstrates how to use ErrAddress.

  Place the following code in a module named TEST.BAS:      DECLARE SUB ErrAddress (modname$, SEG segment%, SEG offset%) 1 ON ERROR GOTO errorHandler 2 ERROR 6 ' cause overflow error 3 END errorHandler: 4 CALL ErrAddress(a$, segment%, offset%) 5 PRINT &quot;error in &quot;; a$; &quot; line&quot;; ERL; &quot;offset &quot;; HEX$(offset%) 6 ON ERROR GOTO 0   Compile and link by using these commands:      BC /O /E TEST.BAS,,TEST.LST; LINK TEST.OBJ ERR.OBJ;   Run TEST.EXE.

TEST.EXE prints the offset of the error (0043). In TEST.LST, this offset appears just after the line that caused the error: <pre class="FIXEDTEXT">     Offset  Data    Source Line ...     003A   0006    2 ERROR 6  ' cause overflow error 0043  0006    3 END </li></ol>

Additional query words: VBmsdos trappable 1.00 softlib ERRADDR.EXE kbfile

Keywords :

Version : MS-DOS:1.0

Platform : MS-DOS

Issue type :
 * }