Q45451: CLEAR Resets ON ERROR GOTO and Turns Off Error Trapping
Article: Q45451 Product(s): See article Version(s): 3.00 4.00 4.00b 4.50 Operating System(s): MS-DOS Keyword(s): ENDUSER | SR# S890224-103 B_BasicCom | mspl13_basic Last Modified: 13-DEC-1989 The CLEAR statement in a QuickBASIC program turns off error handling routines. Any error that happens after a CLEAR statement is not trapped by an error handling routine that was initiated before the CLEAR statement. To trap errors after a CLEAR statement, you must reinstate the error handling routine with a new ON ERROR GOTO clause. This applies to Microsoft QuickBASIC Versions 3.00, 4.00, 4.00b, and 4.50, and Microsoft BASIC Compiler Versions 6.00, 6.00b for MS-DOS and MS OS/2, and Microsoft BASIC PDS 7.00 for MS-DOS and MS OS/2. The following two programs show an error trapping routine that does not work correctly and an error trapping routine that does work: Program 1 --------- REM This error handling routine will not trap the error. ON ERROR GOTO Handler CLEAR REM The ERROR handling routine is now turned off ERROR 1 END Handler: Print "In the ERROR Handler" RESUME The output for this program is only an error message from QuickBASIC. Program 2 --------- REM This ERROR Handling routine will trap the error. ON ERROR GOTO Handler CLEAR REM The ERROR Handling routine is now turned off. ON ERROR GOTO Handler REM The ERROR Handling routine is now turned back on. ERROR 1 END Handler : Print "In the ERROR Handler" RESUME The output for this program is as follows: In the ERROR Handler
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.