Hello Philip,
Thanks for answering. I am afraid your example assumes I have control over the how the errors are thrown in the first place - that is not the case.
Unfortunately this is not possible in the two scenarios I'm interested in: Sandboxes and testing libraries. The "hosted code", that is, the sandboxed code in the case of the sandbox and the tests in the case of a testing library, is out of bounds. I am not writing it, and it's probable that it doesn't even exist at the moment. I have no control over what kind of errors it throws: it could be a table, an integer, a string, or a userdata.
In both the testing library and in the sandbox I need to do some "cleanup" after every piece of "hosted" code is run, regardless of whether it threw an error or not.
This is where I have the issue. With the current Lua implementation, as far as I know, I am left with 2 options:
* I either wrap the error in a table and append the traceback as a field on it, but this changes the error semantics (the initial error was a userdata, but the raised error is a table) or
* I raise the same error again, but then the traceback information is lost (the traceback data that appears is the one of my sandbox / testing lib, not the one where the error originally happened).
Hence my suggestion of adding a 'traceback' param to error.
I hope this explains my situation a bit better.
Regards,
Enrique