# Pre-RFC: Catching Functions

**URL:** <https://internals.rust-lang.org/t/pre-rfc-catching-functions/6505>\
**Category:** language design\
**Created:** [January 8, 2018, 11:33pm UTC](https://internals.rust-lang.org/t/pre-rfc-catching-functions/6505 "2018-01-08T23:33:02Z")\
**Posts on this page:** 1\
**Showing post:** 70

<div class="post-metadata">

**Author:** ![newpavlov](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/newpavlov/32/3290_2.png) [@newpavlov](https://internals.rust-lang.org/u/newpavlov)\
**Post date:** [January 10, 2018, 6:00am UTC](https://internals.rust-lang.org/t/pre-rfc-catching-functions/6505/70 "2018-01-10T06:00:20Z")

</div>

I like idea behind `throw`, but `T catch E` as a sugar for `Result<T, E>` looks quite unnecessary to me and hides `enum` nature of error handling, which I think will hurt learnability. The only case for which it looks a bit useful is when return type is `Result<(), E>`, but I am not sure if it’s enough for such addition. Also as was noted by others usage of throw/catch will probably be a big source of confusion for newcommers. Same goes for `Ok` wrapping, while I too don’t like `Ok(())` that much, I don’t think that hiding it behind magic is a good idea, especially considering that this behaviour will be non-generic.

I would like to have instead two new keywords (lets call them `reta` and `retb` for now) which will work in conjunction with this trait:

```rust
trait RetTrait {
    type A;
    type B;

    fn reta(val: Self::A) -> Self;
    fn retb<V: Into<Self::B>>(val: V) -> Self;
}

impl<T, E> RetTrait for Result<T, E> {
    type A = T;
    type B = E;
    
    fn reta(val: Self::A) -> Self {
        Ok(val)
    }
    
    fn retb<V: Into<Self::B>>(val: V) -> Self {
        Err(val.into())
    }
}

```

So if we’ll write `reta 1;` in case of `Result` it will be sugar for `return Ok(1);` and `retb "error text";` will be sugar for `return Err(From::from("error text"));`. And it can be easily extended to other types.

---

_[View the full topic](https://internals.rust-lang.org/t/pre-rfc-catching-functions/6505)._
