Skip to content

Commit 4288a75

Browse files
committed
add syntax as an unresolved question
1 parent ef6bb5c commit 4288a75

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

active/0000-trait-based-exception-handling.md

+38-7
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ that block). This works for any block, not only loops.
146146
A completely artificial example:
147147

148148
'a: {
149-
let my_thing = if have_thing {
149+
let my_thing = if have_thing() {
150150
get_thing()
151151
} else {
152152
break 'a None
@@ -271,6 +271,37 @@ Without any attempt at completeness, here are some things which should be true:
271271
* `try { Ok(foo()?) } catch e { Err(e) }` = `foo()`
272272

273273

274+
# Unresolved questions
275+
276+
## Choice of keywords
277+
278+
The RFC to this point uses the keywords `try`..`catch`, but there are a number of other possibilities, each with different advantages and drawbacks:
279+
280+
* `try { ... } catch { ... }`
281+
282+
* `try { ... } match { ... }`
283+
284+
* `try { ... } handle { ... }`
285+
286+
* `catch { ... } match { ... }`
287+
288+
* `catch { ... } handle { ... }`
289+
290+
* `catch ...` (without braces or a second clause)
291+
292+
Among the considerations:
293+
294+
* Simplicity. Brevity.
295+
296+
* Following precedent from existing, popular languages, and familiarity with respect to analogous constructs in them.
297+
298+
* Fidelity to the constructs' actual behavior. For instance, the first clause always catches the "exception"; the second only branches on it.
299+
300+
* Consistency with the existing `try!()` macro. If the first clause is called `try`, then `try { }` and `try!()` would have essentially inverse meanings.
301+
302+
* Language-level backwards compatibility when adding new keywords. I'm not sure how this could or should be handled.
303+
304+
274305
# Drawbacks
275306

276307
* Increases the syntactic surface area of the language.
@@ -291,7 +322,9 @@ Without any attempt at completeness, here are some things which should be true:
291322

292323
* Don't.
293324

294-
* Only add the `?` operator, but not `try`..`catch`.
325+
* Only add the `?` operator, but not `try` and `try`..`catch`.
326+
327+
* Only add `?` and `try`, but not `try`..`catch`.
295328

296329
* Instead of a built-in `try`..`catch` construct, attempt to define one using
297330
macros. However, this is likely to be awkward because, at least, macros may
@@ -312,10 +345,10 @@ Without any attempt at completeness, here are some things which should be true:
312345
serious an issue this would actually be in practice, I don't know - there's
313346
reason to believe that it would be much less of one than in C++.
314347

315-
[notes]: https://github.com/glaebhoerl/rust-notes/blob/268266e8fbbbfd91098d3bea784098e918b42322/my_rfcs/Exceptions.txt
316-
317348
* Wait (and hope) for HKTs and generic monad sugar.
318349

350+
[notes]: https://github.com/glaebhoerl/rust-notes/blob/268266e8fbbbfd91098d3bea784098e918b42322/my_rfcs/Exceptions.txt
351+
319352

320353
# Future possibilities
321354

@@ -377,7 +410,6 @@ This `match e` is quite redundant and unfortunate.
377410
Therefore, neither form can be considered strictly superior to the other, and it
378411
may be preferable to simply provide both.
379412

380-
381413
## `throw` and `throws`
382414

383415
It is possible to carry the exception handling analogy further and also add
@@ -398,11 +430,10 @@ both "normal" and "throwing" code paths and (apart from `?` to propagate
398430
exceptions) matches what code might look like in a language with native
399431
exceptions.
400432

401-
402433
## Generalize over `Result`, `Option`, and other result-carrying types
403434

404435
`Option<T>` is completely equivalent to `Result<T, ()>` modulo names, and many common APIs
405-
use the `Option` type, so it would make sense to extend all of the above syntax to `Option`,
436+
use the `Option` type, so it would be useful to extend all of the above syntax to `Option`,
406437
and other (potentially user-defined) equivalent-to-`Result` types, as well.
407438

408439
This can be done by specifying a trait for types which can be used to "carry" either a normal

0 commit comments

Comments
 (0)