On Error Statement


On Error { GoTo line | Resume Next | GoTo 0 }

Sets BlueZone Basic’s error-handling method and if applicable specifies the line label of the error-handling routine.

The line parameter refers to a label.  That label must be present in the code or an error is generated.

Example:

    Sub Main

        On Error GoTo dude   ' Turn on error checking

        Dim x as object

        x.draw   ' Object not set

        jpe   ' Undefined function call

        print 1/0   ' Division by zero

        Err.Raise 6   ' Generate an "Overflow" error

        MsgBox "Back"

        MsgBox "Jack"

        Exit Sub

 

    dude:

        On Error Resume Next   ' turn off error checking

        MsgBox "HELLO"

        Print Err.Number, Err.Description

        Resume Next

        MsgBox "Should not get here!"

        MsgBox "What?"

        On Error Goto 0   ' turn on error checking

    End Sub

Errors can be raised with the syntax:

Err.Raise x

The list below shows the corresponding descriptions for the defined values of x.

5:  "Invalid procedure call";

6:  "Overflow";

7:  "Out of memory";

9:  "Subscript out of range";

10: "Array is fixed or temporarily locked";

11: "Division by zero";

13: "Type mismatch";

14: "Out of string space";

16: "Expression too complex";

17: "Can't perform requested operation";

18: "User interrupt occurred";

20: "Resume without error";

28: "Out of stack space";

35: "Sub, Function, or Property not defined";

47: "Too many DLL application clients";

48: "Error in loading DLL";

49: "Bad DLL calling convention";

51: "Internal error";

52: "Bad file name or number";

53: "File not found";

54: "Bad file mode";

55: "File already open";

57: "Device I/O error";

58: "File already exists";

59: "Bad record length";

60: "Disk full";

62: "Input past end of file";

63: "Bad record number";

67: "Too many files";

68: "Device unavailable";

70: "Permission denied";

71: "Disk not ready";

74: "Can't rename with different drive";

75: "Path/File access error";

76: "Path not found";

91: "Object variable or With block variable not set";

92: "For loop not initialized";

93: "Invalid pattern string";

94: "Invalid use of Null";

 

// OLE Automation Messages

429: "OLE Automation server cannot create object";

430: "Class doesn't support OLE Automation";

432: "File name or class name not found during OLE Automation operation";

438: "Object doesn't support this property or method";

440: "OLE Automation error";

443: "OLE Automation object does not have a default value";

445: "Object doesn't support this action";

446: "Object doesn't support named arguments";

447: "Object doesn't support current local setting";

448: "Named argument not found";

449: "Argument not optional";

450: "Wrong number of arguments";

451: "Object not a collection";

 

// Miscellaneous Messages

444: "Method not applicable in this context";

452: "Invalid ordinal";

453: "Specified DLL function not found";

457: "Duplicate Key";

460: "Invalid Clipboard format";

461: "Specified format doesn't match format of data";

480: "Can't create AutoRedraw image";

481: "Invalid picture";

482: "Printer error";

483: "Printer driver does not supported specified property";

484: "Problem getting printer information from from the system.";

 

// Make sure the printer is setp up correctly.

485: "invalid picture type";

520: "Can't empty Clipboard";

521: "Can't open Clipboard";