<div dir="ltr">Guess I found the answer:<div><br></div><div><div>1> bank_server:start_link(). </div><div>{ok,<0.562.0>}</div><div><br></div><div>2> self().</div><div><0.559.0></div><div><br></div><div>3> exit(self(), kill).</div><div>** exception exit: killed</div><div><br></div><div>4> self(). </div><div><0.565.0></div><div><br></div><div>5> whereis(bank_server). </div><div>undefined</div></div><div><br></div><div>Thank you!</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 27, 2015 at 1:00 PM, Vimal Kumar <span dir="ltr"><<a href="mailto:vimal7370@gmail.com" target="_blank">vimal7370@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><font face="arial, helvetica, sans-serif">Hi all,</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">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. </font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">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).</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">1> bank_server:start_link().</font></div><div><font face="arial, helvetica, sans-serif">{ok,<0.549.0>}</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">2> whereis(bank_server).</font></div><div><font face="arial, helvetica, sans-serif"><0.549.0></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">3> bank_server:new_user(user1, "mysecretpass1").</font></div><div><font face="arial, helvetica, sans-serif">{ok}</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">4> {_, SecretKey1} = bank_server:login(user1, "mysecretpass1").</font></div><div><font face="arial, helvetica, sans-serif">{ok,"lYWrBFIi7CoeYN8KSK3QgA=="}</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">5> bank_server:deposit(user1, SecretKey1, 10.00). </font></div><div><font face="arial, helvetica, sans-serif">{ok,success}</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">6> bank_server:check_balance(user1, SecretKey1). </font></div><div><font face="arial, helvetica, sans-serif">{ok,10.0}</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">7> bank_server:new_user(user2, "mysecretpass2"). </font></div><div><font face="arial, helvetica, sans-serif">{ok}</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">8> {_, SecretKey1} = bank_server:login(user2, "mysecretpass2").</font></div><div><font face="arial, helvetica, sans-serif">** exception error: no match of right hand side value {ok, "vYaWQbNQvROqXybVf424lQ=="}</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">9> whereis(bank_server).</font></div><div><font face="arial, helvetica, sans-serif">undefined</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">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 it?</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">I am yet to learn OTP supervisors, but I believe it might have restarted the server without any delay in such a crash. </font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">The complete code for bank_server.erl is available at <a href="http://pastebin.com/4bMWjNG7" target="_blank">http://pastebin.com/4bMWjNG7</a> to check.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Thank you!</font></div></div>
</blockquote></div><br></div>