Non-typed errors in catch

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Non-typed errors in catch

Salikhov Dinislam
Hello,

I have the following module:
-module(exception).

-export([
    foo/1
]).

foo(Any) ->
    try Any + 1 of
        Any -> ok
    catch
        Error -> {not_typed, Error};                 % warn?
        any:Error -> {any_error, Error};           % warn?
        Type:Error -> {typed_error, {Type, Error}}
    end.
Compiler doesn't complain about the marked lines. Neither does dialyzer.
Is there any rationale for such behaviour? Or is it a bug?

P.S. I use Erlang/OTP 20 [erts-9.3.2].

Regards,
Dinislam Salikhov

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Non-typed errors in catch

John Krukoff-2
I’ve no insight into why the set of valid exception classes isn’t restricted to the 3 the run time can actually create, but can at least point to the explanation of why `catch Error ->` is valid:

> It is allowed to omit Class and Stacktrace. An omitted Class is shorthand for throw:

from: http://erlang.org/doc/reference_manual/expressions.html#try

And illustrated by:

```
> try throw(broke) catch Error -> {throw, Error} end.
{throw,broke}
```

--
John Krukoff
[hidden email]

From: [hidden email] <[hidden email]> On Behalf Of Salikhov Dinislam
Sent: Thursday, May 16, 2019 10:08
To: Erlang/OTP discussions <[hidden email]>
Subject: [erlang-questions] Non-typed errors in catch

Hello,

I have the following module:
-module(exception).

-export([
    foo/1
]).

foo(Any) ->
    try Any + 1 of
        Any -> ok
    catch
        Error -> {not_typed, Error};                 % warn?
        any:Error -> {any_error, Error};           % warn?
        Type:Error -> {typed_error, {Type, Error}}
    end.
Compiler doesn't complain about the marked lines. Neither does dialyzer.
Is there any rationale for such behaviour? Or is it a bug?

P.S. I use Erlang/OTP 20 [erts-9.3.2].

Regards,
Dinislam Salikhov

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

smime.p7s (8K) Download Attachment