Skip to content

Commit 6381d9d

Browse files
committed
Add explanation about restrictions to docs
1 parent 2c5613c commit 6381d9d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/docs/reference/experimental/canthrow.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@ closure may refer to capabilities in its free variables. This means that `map` i
179179
already effect polymorphic even though we did not change its signature at all.
180180
So the takeaway is that the effects as capabilities model naturally provides for effect polymorphism whereas this is something that other approaches struggle with.
181181

182+
**Note 1:** The compiler will only treat checked exceptions that way. An exception type is _checked_ if it is a subtype of
183+
`Exception` but not of `RuntimeException`. The signature of `CanThrow` still admits `RuntimeException`s since `RuntimeException` is a proper subtype of its bound, `Exception`. But no capabilities will be generated for `RuntimeException`s. Furthermore, `throws` clauses
184+
also may not refer to `RuntimeException`s.
185+
186+
**Note 2:** To keep things simple, the compiler will currently only generate capabilities
187+
for catch clauses of the form
188+
```scala
189+
case ex: Ex =>
190+
```
191+
where `ex` is an arbitrary variable name (`_` is also allowed), and `Ex` is an arbitrary
192+
checked exception type. Constructor patterns such as `Ex(...)` or patterns with guards
193+
are not allowed. The compiler will issue an error if one of these is used to catch
194+
a checked exception and `saferExceptions` is enabled.
195+
182196
## Gradual Typing Via Imports
183197

184198
Another advantage is that the model allows a gradual migration from current unchecked exceptions to safer exceptions. Imagine for a moment that `experimental.saferExceptions` is turned on everywhere. There would be lots of code that breaks since functions have not yet been properly annotated with `throws`. But it's easy to create an escape hatch that lets us ignore the breakages for a while: simply add the import

0 commit comments

Comments
 (0)