Good suggestion. I’ve implemented this for the next release, with a slightly different API.
https://feedback.objo.dev/feature/1358
Rather than adding a DetailedMessage string, RuntimeException now has a read-only ThrowSite property. It returns the StackFrame where the exception originated:
Try
LoadData()
Catch ex As IOException
Print(ex.Message)
If ex.ThrowSite <> Nothing Then
Print(ex.ThrowSite.ToString())
End If
End Try
This produces output such as:
Unexpected end of stream.
App.ReadStr (App:513)
ThrowSite is equivalent to StackFrames[0], but avoids manually indexing and formatting the stack when you only need the failure location.
I also added StackFrame.ToString(), which formats any frame as:
Name (FileName:LineNumber)
The existing Message property remains unchanged, and StackFrames is still available when you need the complete call stack:
For Each frame As StackFrame In ex.StackFrames
Print(frame.ToString())
Next
Rethrowing an exception preserves its original ThrowSite and stack frames. Thanks for the suggestion!