Catches and returns the exception thrown from the given expression.
If no exception is thrown, then null is returned. E can be
void.
Note that while collectExceptioncan be used to collect any
Throwable and not just Exceptions, it is generally ill-advised to
catch anything that is neither an Exception nor a type derived from
Exception. So, do not use collectException to collect
non-Exceptions unless you're sure that that's what you really want to
do.
Catches and returns the exception thrown from the given expression. If no exception is thrown, then null is returned. E can be void.
Note that while collectException can be used to collect any Throwable and not just Exceptions, it is generally ill-advised to catch anything that is neither an Exception nor a type derived from Exception. So, do not use collectException to collect non-Exceptions unless you're sure that that's what you really want to do.