[erlang-questions] Why does this crash?

Vimal Kumar vimal7370@REDACTED
Sun Sep 27 09:30:30 CEST 2015

Hi all,

Erlang newbie here. This is my first attempt to write an OTP module myself
- a simple bank server. API functions allow users to register, login,
deposit/withdraw money to/from their own account.

The bank_server:login/2 function returns a secret key (sort of unique
session id, lets assume) which is required for further meaningful
transactions (like bank_server:deposit/3 or bank_server:withdraw/3).

1> bank_server:start_link().

2> whereis(bank_server).

3> bank_server:new_user(user1, "mysecretpass1").

4> {_, SecretKey1} = bank_server:login(user1, "mysecretpass1").

5> bank_server:deposit(user1, SecretKey1, 10.00).

6> bank_server:check_balance(user1, SecretKey1).

7> bank_server:new_user(user2, "mysecretpass2").

8> {_, SecretKey1} = bank_server:login(user2, "mysecretpass2").
** exception error: no match of right hand side value {ok,

9> whereis(bank_server).

In line 8, I understand that I should have used a different variable, since
SecretKey1 already has a value. But I am curious why a simple mistake ***
from client side *** crashed the server itself? Is there any way to avoid

I am yet to learn OTP supervisors, but I believe it might have restarted
the server without any delay in such a crash.

The complete code for bank_server.erl is available at
http://pastebin.com/4bMWjNG7 to check.

Thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150927/e5948bff/attachment.htm>

More information about the erlang-questions mailing list