Just throwing an idea out there: do the same as for pointers with unknown nullability.
func maybeThisCanThrow() throws!
This is an implicitly trapping throwing function: exceptions thrown from that function will trap unless the caller makes the call within a try
expression:
try maybeThisCanThrow() // now you handle the exception
maybeThisCanThrow() // implicitly prefixed with `try!`
The compiler won't emit an error if you fail to use try
, it'll just trap as if you had written try!
. This is similar to implicitly unwrapped nil
pointers.
Note that this behavior can be added later. I don't think there's a conflict with what is proposed here. Implicitly trapping throws!
can be a future direction.