# ErrObject class

The **Err** object holds information about the most recent run-time error. It is a global, intrinsic singleton --- there is no need to declare it or construct one with **New**, just reference it as **Err**. The default property is [**Number**](/tB/Modules/ErrObject/Number.md), so a bare **Err** is equivalent to `Err.Number`.

## Inspecting an error

When a run-time error is raised inside a procedure that has an active error handler installed with [**On Error**](/tB/Core/On-Error.md), execution jumps to the handler with the **Err** object's properties populated. The handler reads [**Number**](/tB/Modules/ErrObject/Number.md) to identify the error, [**Description**](/tB/Modules/ErrObject/Description.md) for a human-readable message, and [**Source**](/tB/Modules/ErrObject/Source.md) to learn where it originated.

```tb check_build
Sub Demo()
    On Error GoTo Handler
    Err.Raise 6                    ' Generate an Overflow error.
    Exit Sub
Handler:
    Debug.Print Err.Number         ' 6
    Debug.Print Err.Description    ' "Overflow"
End Sub
```

The properties are reset to their zero values when the handler exits via **Resume**, **Resume Next**, or any **Exit** statement, or when [**Clear**](/tB/Modules/ErrObject/Clear.md) is called explicitly.

## Raising a custom error

Code can generate its own run-time error by calling [**Raise**](/tB/Modules/ErrObject/Raise.md). Custom error numbers should be biased by [**vbObjectError**](/tB/Modules/Constants/index.md#vbObjectError) so that they don't collide with twinBASIC's built-in numbers. Setting [**Source**](/tB/Modules/ErrObject/Source.md) and [**Description**](/tB/Modules/ErrObject/Description.md) at the call site gives the error handler something useful to inspect or display.

```tb check_build
Public Sub WithdrawCash(ByVal Amount As Currency)
    If Amount > Balance Then
        Err.Raise vbObjectError + 1001, _
                  Source:="Account.WithdrawCash", _
                  Description:="Insufficient funds."
    End If
    ' ...
End Sub
```

## Members

- [Clear](/tB/Modules/ErrObject/Clear.md) -- resets all properties of the **Err** object to their zero values
- [Description](/tB/Modules/ErrObject/Description.md) -- returns or sets a string describing the error
- [HelpContext](/tB/Modules/ErrObject/HelpContext.md) -- returns or sets the context ID of a Help topic associated with the error
- [HelpFile](/tB/Modules/ErrObject/HelpFile.md) -- returns or sets the path to the Help file associated with the error
- [LastDllError](/tB/Modules/ErrObject/LastDllError.md) -- returns the last system error code from a call into a DLL
- [LastHresult](/tB/Modules/ErrObject/LastHresult.md) -- returns the last HRESULT returned from a COM object method call
- [Number](/tB/Modules/ErrObject/Number.md) -- returns or sets the error number; the default member of **Err**
- [Raise](/tB/Modules/ErrObject/Raise.md) -- generates a run-time error
- [ReturnHResult](/tB/Modules/ErrObject/ReturnHResult.md) -- sets a custom HRESULT to be returned from the current method
- [Source](/tB/Modules/ErrObject/Source.md) -- returns or sets the name of the object or application that generated the error
