onerror()
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)
}