Type/to search
Getting Started
Platform Basics
Writing Strategies
Strategy Structure
init()
onexit()
onerror()
Main Loop
Event-Driven
Programming Languages
Strategy Parameters
Interactive Controls
Strategy Frontend
Template Library
Built-in Libraries
UI Text Localization
API Quick Reference
Development Tools
Backtesting System
Advanced Topics
Data and Research
Extended API Interface

Optional exception handler, JavaScript only: called when main() ends with an uncaught exception; the argument msg is the error message. When onerror() is called, onexit() is not. It may run for at most 5 minutes and is terminated when it exceeds that.

The backtesting system does not support this function, and neither do Python and Rust strategies.

Examples

An out-of-range array access in main() raises an exception, and onerror() logs the error message.

javascript
function main() { var arr = [] Log(arr[6].Close) // deliberately raise an exception here } function onerror(msg) { Log("Error:", msg) }