I posted about a related thing a long time ago and this "unwrap or throw" operator:
was the solution that came up which ultimately solved the problem for me at least well enough that I stopped pestering the forums for a better solution.
try sendEmail(
to: user|?.email, // `user` is an optional
body: "Hello"
)
In this case sendEmail
is not a throwing function, rather if user
is nil
then the whole expression will fail to execute and instead throw the error that user
was nil.
I admit that this has burned me a number of times in the form of a try?
statement which was originally placed for the sake of ignoring one of these nil error also inadvertently ending up swallowing an important other error.