Skip to content

Commit 1c353ab

Browse files
committed
Fix typos
1 parent 04774ba commit 1c353ab

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/docs/reference/experimental/canthrow.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ a function `f` like this:
117117
val limit = 10e9
118118
class LimitExceeded extends Exception
119119
def f(x: Double): Double =
120-
if x < limit then f(x) else throw LimitExceeded())
120+
if x < limit then x * x else throw LimitExceeded()
121121
```
122122
You'll get this error message:
123123
```
@@ -136,7 +136,7 @@ You'll get this error message:
136136
As the error message implies, you have to declare that `f` needs the ability to throw a `LimitExceeded` exception. The most concise way to do so is to add a `canThrow` clause:
137137
```scala
138138
def f(x: Double): Double canThrow LimitExceeded =
139-
if x < limit then f(x) else throw LimitExceeded())
139+
if x < limit then x * x else throw LimitExceeded()
140140
```
141141
Now put a call to `f` in a `try` that catches `LimitExceeded`:
142142
```scala
@@ -192,7 +192,7 @@ To summarize, the extension for safer exception checking consists of the followi
192192
- It augments the type checking of `throw` by _demanding_ a `CanThrow` ability or the thrown exception.
193193
- It augments the type checking of `try` by _providing_ `CanThrow` abilities for every caught exception.
194194

195-
That's all. It's quite noteable that one can do exception checking in this way without any special additions to the type system. We just need regular givens and context functions. Any runtime overhead is eliminated using `erased`.
195+
That's all. It's quite remarkable that one can do exception checking in this way without any special additions to the type system. We just need regular givens and context functions. Any runtime overhead is eliminated using `erased`.
196196

197197
## Caveats
198198

@@ -218,7 +218,7 @@ With the system presented here, this function typechecks, with expansion
218218
def escaped(xs: Double*): () => Int =
219219
try
220220
given ctl: CanThrow[LimitExceeded] = ???
221-
() => xs.map(f(using ctl)).sum
221+
() => xs.map(x => f(x)(using ctl)).sum
222222
catch case ex: LimitExceeded => -1
223223
```
224224
But if you try to call `escaped` like this
@@ -237,5 +237,5 @@ And it would have many other applications besides: Exceptions are a special case
237237

238238
But even without these additional mechanisms, exception checking is already useful as it is. It gives a clear path forward to make code that uses exceptions safer, better documented, and easier to refactor. The only loophole arises for scoped abilities - here we have to verify manually that these abilities do not escape. Specifically, a `try` always has to be placed in the same computation stage as the throws that it enables.
239239

240-
Put another way: If the status quo is 0% static checking since 100% is too painful, then an alternative that gives you to 95% static checking with great ergonomics looks like a win. And we might still get to 100% in the future.
240+
Put another way: If the status quo is 0% static checking since 100% is too painful, then an alternative that gives you 95% static checking with great ergonomics looks like a win. And we might still get to 100% in the future.
241241

0 commit comments

Comments
 (0)