문제

I'm new to Erlang. Right now, I'm learning about linking of processes. I've confused a bit after next experiments:

3> process_flag( trap_exit, true ).
false
4> try 1+1, spawn_link( unknown_module, unknown_function, [] ) of
4> Pid -> Pid
4> catch
4> _:_ -> err
4> end.
<0.37.0>
5> 
=ERROR REPORT==== 18-Jul-2012::16:01:32 ===
Error in process <0.37.0> with exit value: {undef,[{unknown_module,unknown_function,[],[]}]}


5> 
5> flush().
Shell got {'EXIT',<0.37.0>,{undef,[{unknown_module,unknown_function,[],[]}]}}
ok

As I expected, I've got Pid from created process, and that process failed - because of unknown module and function - so I've got back message about it.

After that I've tried next:

6> try spawn_link( unknown_module, unknown_function, [] ) of     
6> Pid -> Pid
6> catch
6> _:_ -> err
6> end.
** exception error: no try clause matching <0.40.0>

And I don't understand why interpreter process can't extract Pid and fails

Thanks

P.S.

In a few words: why next code breaks interpreter process (** exception error: no try clause matching <0.40.0>)

try spawn_link( unknown_module, unknown_function, [] ) of     
   Pid -> Pid
catch
   _:_ -> err
end.

and why this code, doesn't break interpreter process (returns <0.37.0>)

try 1+1, spawn_link( unknown_module, unknown_function, [] ) of     
   Pid -> Pid
catch
   _:_ -> err
end.

???

도움이 되었습니까?

해결책

Ohh... I've forgot that variable Pid has been already binded with value (after calling of first try-catch block). So all I needed - was unbinding variable Pid. Calling in interpreter f(Pid). - solved my problem

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top