# SetThreadGlobalErrorTrap
{: .no_toc }

Registers a global callback that fires when an unhandled run-time error is raised on the calling thread.

Syntax: **SetThreadGlobalErrorTrap** *CallbackAddress*

*CallbackAddress*
: *required* **LongPtr**. The address of a callback procedure, typically obtained with **AddressOf**. Pass `0` to clear the trap.

The trap supplements ordinary `On Error` handling: it sees errors that escape the active error handler chain on the thread that registered it, and is called before the runtime decides what to do next (display the unhandled-error dialog, end the program, etc.). Useful for wiring up application-wide logging or crash reporting.

Only one trap is active per thread; setting a new one replaces the previous.

### Common Errors

| Error | When |
|---|---|
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *CallbackAddress* is **Null** |

### See Also

- [On Error](/tB/Core/On-Error.md) statement
- [Err object](/tB/Modules/ErrObject/index.md)
