Having done my type checker, I'm thinking on targetting C++. How can I efficiently add debugging information to thrown exceptions?
Similiar to JavaScript, you can throw anything. Error
, when created, should have its call stack information based from where its constructor was invoked. Error
s may be created and thrown indirectly, like:
const e = new Error
throw e
Basically what I thought is that I can have a global, program-static stack, in the systems language side, holding such debug information, so it'd look like:
callStackDebug = [
'[top-level] at index.vs:1',
'f() at index.vs:3',
]
For this example:
f()
function f(): void {
throw new Error('Message')
}
Then you get something like:
Error: Message
- at
f()
at index.vs:3- at [top-level] at index.vs:1
However, I'm worried that this program-static debug information stack may not work for asynchronous functions or concurrent code. It may also be problematic in case code suspends due to a throw
and an exception handler catches it, leading to wrong information:
try {
// ...
} catch (e: RangeError) {
// ...
}
// debug information can be incorrect now due to call depth?
Considering I'm going to target C++, I ask, how can I overcome this?