[erlang-questions] Why does this crash?
Dmitry Klionsky
dm.klionsky@REDACTED
Sun Sep 27 13:10:25 CEST 2015
shell:catch_exception/1 is another trick for shell.
You don't need to unlink the process as the shell isn't get killed if
exceptions happen.
1> self().
<0.34.0>
2> 1/0.
** exception error: an error occurred when evaluating an arithmetic
expression
in operator '/'/2
called as 1 / 0
3> self().
<0.37.0>
4> catch_exception(true).
false
5> 1/0.
* exception error: an error occurred when evaluating an arithmetic
expression
in operator '/'/2
called as 1 / 0
6> self().
<0.37.0>
7>
On 09/27/2015 01:28 PM, Vimal Kumar wrote:
> Hi Jesper,
>
> I now implemented supervision trees along with the application
> controller, and things now work as it should be.
>
> 1> application:start(mybank).
> ok
>
> 2> whereis(bank_server).
> <0.38.0>
>
> 3> bank_server:new_user(user1, "d3fault").
> {ok}
>
> 4> {_, UniqueId} = bank_server:login(user1, "d3fault").
> {ok,"OsNTJVIQgyb9ERHg3q9SLg=="}
>
> 5> bank_server:new_user(user2, "d3fault").
> {ok}
>
> 6> {_, UniqueId} = bank_server:login(user2, "d3fault").
> ** exception error: no match of right hand side value {ok,
> "w7MJ1HQrHIDbVlNOh5bSpg=="}
>
> 7> whereis(bank_server).
> <0.38.0>
>
> Unlinking the process is a great tip for testing from shell, didn't
> cross my mind.
>
> Thanks!
>
> On Sun, Sep 27, 2015 at 3:24 PM, Jesper Louis Andersen
> <jesper.louis.andersen@REDACTED
> <mailto:jesper.louis.andersen@REDACTED>> wrote:
>
>
> On Sun, Sep 27, 2015 at 10:52 AM, Vimal Kumar <vimal7370@REDACTED
> <mailto:vimal7370@REDACTED>> wrote:
>
> Going to add supervisors into this system and learn more about it.
>
>
> It doesn't happen in real systems, because the supervision trees
> are linked to the application controller, and not the shell. If
> you simply add a supervision tree, and link that tree to the
> shell, you are usually not free of the problem.
>
> When developing however, you can unlink the pid:
>
> {ok, P} = foo:start_link().
> unlink(P).
>
> which will have P not die if the shell does.
>
> The other resources to look out for are ETS tables, and port()'s,
> that is network sockets and files. If their controlling process,
> i.e. the shell, goes away, then that resource is
> cleaned/reaped/closed again.
>
>
> --
> J.
>
>
>
>
> _______________________________________________
> 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/20150927/0e431f34/attachment.htm>
More information about the erlang-questions
mailing list