Name

Error Statement

Syntax

Error [errornumber]
errornumber

Use: Optional

Data Type: Long

Any valid error code

Description

Raises an error

Rules at a glance

The Error statement is included only for backward compatibility; instead, if you’re using standard Visual Basic error handling, you should use the Err.Raise method and the Err object. Otherwise, you should use structured exception handling with the Try...Catch construct.

Programming Tips and Gotchas

The Error statement has been a “compatibility” statement for several versions of Visual Basic. Interestingly, it managed to survive the general purge of outdated language elements. Despite its persistence, we still recommend that its use be strictly avoided.

Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.