This looks great, excited to see it come to fruition.
It immediately makes me think of a potential future direction that plays into the discussion around the elusive type throws.
One of the issues in that discussion was that while most felt it had strong use cases around local control flow, there was some reticence around moving forward with the feature due to the potential of 'abuse', and a proliferation of overly rigorous Error types with deeply nested sub errors.
A quote from that disucussion:
However, there was one fairly reasonable use case for nested errors: and that was to create a pseudo backtrace from where an Error was thrown to bubble up to the application layer and diagnose where/why an Error occurred.
It seems that the feature pitched in this thread would be really useful in helping programmers supersede that practice, if there was some way of enclosing throwing code in a block that would 'collect' a backtrace at the precise point an error was thrown (and/or rethrown), it would be a really powerful thing for production debugging.
Something along the lines of:
do {
try callIntoDeeplyNestedLibraryWhichThrowsInVariousPlaces()
}
catch let error: KnownError {
// deal with a _known_ error as usual
...
}
catch _, let backtraces {
// gather backtraces and report via developer chosen, application level library/utility
Log.nonFatalErrors(backtraces)
}
I'm not sure how performance intensive this would be, but if it could be done without too much performance impact (and conditionally on enclosure of a catch that included that second param, it might be a really nice feature to have.
And hopefully we'd finally see typed throws.