This probably happens with other ASH functions, but I noticed this specifically with substring(), so I'll use that as an example.
> ash substring("test", -1, 4)
Begin index -1 out of bounds ()
Returned: void
> ash substring("test", 4, -1)
Begin index 4 greater than end index -1 ()
Returned: void
Normally this is fine, but if you enclose the above code in a try/finally block, my expectation would be that the code is tried, the exception is thrown and the finally block is then ran. What seems to happen is that KoLmafia stops script execution as soon as the exception is thrown.
I haven't looked at the code, so I don't know if it's simply because try/finally only works with abort/return/break/continue and not actual exceptions. If that's the case, I would suggest that we handle known exceptions within ASH by entering an abort state and printing an error message instead of throwing an exception. This would behave well in normal situations but execute the finally block in a try.
> ash substring("test", -1, 4)
Begin index -1 out of bounds ()
Returned: void
> ash substring("test", 4, -1)
Begin index 4 greater than end index -1 ()
Returned: void
Normally this is fine, but if you enclose the above code in a try/finally block, my expectation would be that the code is tried, the exception is thrown and the finally block is then ran. What seems to happen is that KoLmafia stops script execution as soon as the exception is thrown.
I haven't looked at the code, so I don't know if it's simply because try/finally only works with abort/return/break/continue and not actual exceptions. If that's the case, I would suggest that we handle known exceptions within ASH by entering an abort state and printing an error message instead of throwing an exception. This would behave well in normal situations but execute the finally block in a try.