[erlang-questions] try catch params in Core Erlang

Richard Carlsson carlsson.richard@REDACTED
Fri Oct 23 14:51:28 CEST 2015


The third parameter is described in the Core Erlang specification (
https://www.it.uu.se/research/group/hipe/cerl/doc/core_erlang-1.0.3.pdf),
albeit in a very opaque way. This is because the Core Erlang language
doesn't go into any details about things that can be left to the actual
Erlang implementation to decide how it should work.

The third parameter is the exception object itself. This needs to be an
Erlang term so that it can be handled and passed around, but for
efficiency, the BEAM will pack the necessary info into a bignum, which is a
cheap and compact representation. It will stay like this until someone
really needs to do anything except pass it on upwards, in which case it can
be unpacked to a more readable tuple with a stack trace. This detail is
completely implementation dependent and should not be relied on by
programmers on the Erlang level.


        /Richard

On Mon, Oct 19, 2015 at 10:14 AM, Jonas Falkevik <
jonas.falkevik@REDACTED> wrote:

> It seems to be the stack trace at least in R16B03-1.
>
> erl source:
> -module(test).
> -compile(export_all).
>
> test() ->
>     try
> foo:bar()
>     catch
>         some:thing -> ok;
> error:E ->
>    io:format("third: ~p~n", [E])
>     end.
>
> core erlang modification:
>
> @@ -18,10 +18,10 @@
>        <'some','thing',_cor4> when 'true' ->
>    'ok'
>        %% Line 9
> -      <'error',E,_cor5> when 'true' ->
> +      <'error',_E,F> when 'true' ->
>    %% Line 10
>    call 'io':'format'
> -      ([116|[104|[105|[114|[100|[58|[32|[126|[112|[126|[110]]]]]]]]]]],
> [E|[]])
> +      ([116|[104|[105|[114|[100|[58|[32|[126|[112|[126|[110]]]]]]]]]]],
> [F|[]])
>        ( <_cor3,_cor2,_cor1> when 'true' ->
>      primop 'raise'
>   (_cor1, _cor2)
>
>
>
> Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:4:4]
> [async-threads:10] [hipe] [kernel-poll:false]
>
> Eshell V5.10.4  (abort with ^G)
> 1> c(test, [to_core]).
> ** Warning: No object file created - nothing loaded **
> ok
> 2> c(test, [from_core]).
> {ok,test}
> 3> test:test().
> third: [[{foo,bar,[],[]},
>          {test,test,0,[]},
>          {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,573}]},
>          {shell,exprs,7,[{file,"shell.erl"},{line,674}]},
>          {shell,eval_exprs,7,[{file,"shell.erl"},{line,629}]},
>          {shell,eval_loop,3,[{file,"shell.erl"},{line,614}]}]|
>         -000000000000000016]
> ok
>
> /Jonas
>
> On Oct 15, 2015, at 19:57 , Vladimir Gordeev wrote:
>
> If you compile some try-catch statements into Core Erlang, you may notice,
> that it receives three params in exception pattern:
> http://tryerl.seriyps.ru/#id=3bf3
>
> this:
>
>     try foo:bar()
>     catch
>         some:thing -> ok
>     end.
>
> into this:
>
> try
>    call 'foo':'bar'
> ()
> of <_cor0> ->
>    _cor0
> catch <_cor3,_cor2,_cor1> ->
>    case <_cor3,_cor2,_cor1> of
>      %% Line 7
>      <'some','thing',_cor4> when 'true' ->
>  'ok'
>      ( <_cor3,_cor2,_cor1> when 'true' ->
>    primop 'raise'
> (_cor1, _cor2)
> -| ['compiler_generated'] )
>    end
>
> In "An introduction to Core Erlang" catch described as taking two params:
> http://www.erlang.org/workshop/carlsson.ps
>
> Question is: what is this third param (_cor4) for?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151023/033654cf/attachment.htm>


More information about the erlang-questions mailing list