Hi, does any one thought about concept - "*Explici...
# announcements
a
Hi, does any one thought about concept - "*Explicit Catch Exceptions*"? It would be a kind of exception which can be caught by specifying it explicitly try { } catch (e:ExceptionType) { } and impossible to catch in otheF ways. For e.g. this would solve problems with CancellationException propagation, using flow api. Currently there are cases where we need to explicitly catch and rethrow these "internal" exceptions and code is like: try {} catch (e:CancellationException) { throw e } catch(e:Exception) { } Usage would be annotate exception class with @ExplicitOnly annotation like this:
Copy code
@ExplicitOnly public expect open class CancellationException(message: String?) : IllegalStateException
j
I see the issue, but I wonder if this is just working around bad design... 🤔
d
Catch-all
catch(e:Exception)
looks like a code smell to me.
a
Code smell is that coroutine internals is based on exceptions and programmers cannot freely use try catch statements and must know that there are some MAGIC exceptions which you shouldn't catch.
😉 1
👆 1
p
I wonder if it could be possible to make a compiler plugin that does this.