5.18 throw

Haxe allows throwing any kind of value using its throw syntax:

throw expr

A value which is thrown like this can be caught by catch blocks. If no such block catches it, the behavior is target-dependent.

since Haxe 4.1.0

It's highly recommended to not throw arbitrary values and instead throw instances of haxe.Exception. In fact, if value is not an instance of haxe.Exception, then throw value is compiled as throw haxe.Exception.thrown(value), which wraps value into an instance of haxe.Exception.

However native target exceptions are thrown as-is. For example an instance of cs.system.Exception or php.Exception won't get automatically wrapped upon throwing.