[erlang-questions] dialyzer <-> exceptions

Tobias Lindahl tobias.lindahl@REDACTED
Mon May 5 16:49:47 CEST 2008


Hi Georgy,

Andras Georgy Bekes wrote:
> Hi,
> 
> I've just found that dialyzer is not type checking exceptions.
> 
> What I mean:
> -----------------------------------------
> f()->
>   ok.
> 
> case catch f() of
>    ok ->
>       ok;
>    _ ->
>       nok
> end,
> -----------------------------------------
> Here dializer approximates the type of catch f() to 'any' type, and 
> therefore not complaining about the second, unreachable case.
> 
> With try-catch, things are better:
> -----------------------------------------
> try f() of
>    ok ->
>       ok;
>    _ ->   %% detected as unreachable
>       nok
> catch
>    _:_ -> %% not detected as unrechable
>       something
> end,
> -----------------------------------------
> 
> So it approximates caught or try-caugth exception values with 'any' type 
> even if no exception can occur.

First, I would like to point out that the information Dialyzer can find 
is much better in the try...catch than in the simple catch. I strongly 
encourage the use of the former construct. We recently changed all code 
in the HiPE compiler to use try, and it is not that much work (although 
I wasn't the one doing it ;-) )

> My questions are: Will dialyzer type-check exceptions in the future,
> or this would imply a total rewrite of it and therefore not planned?
> If yes, when?

In principle, Dialyzer could find all the exceptions that can occur, but 
since there would be very many case clauses etc, it is more reasonable 
to limit the tracking to (for example) thrown values. This is something 
we have discussed, and while we are not currently working on it, it will 
probably happen in the future.

I cannot give you any time estimate on this, but in the meantime it will 
probably help both Dialyzer and your code to migrate from using catch to 
try...catch anyway.

Tobias

> 
> 	Georgy
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list