title: Erlang "badarg", Not sure how to handle
body: <p>Before I start, I have already checked out <a href="https://stackoverflow.com/questions/25199963/handle-badarg-in-erlang">Handle badarg in Erlang</a>
  But I am still not successful in my undefined checks so I removed them.</p>
  
  <p>I am building a dummy bank process and when a client does a balance query check to the bank process, the program exits, saying:</p>
  
  <pre><code>Error in process &lt;0.373.0&gt; with exit value:
  {badarg,[{project4,client,3,
                     [{file,"/Users/owner/Desktop/bank.erl"},
                      {line,27}]}]}
  
  =ERROR REPORT==== 26-Oct-2016::13:34:57 ===
  Error in process &lt;0.379.0&gt; with exit value:
  {badarg,[{project4,client,3,
                     [{file,"/Users/owner/Desktop/bank.erl"},
                      {line,27}]}]}
  
  =ERROR REPORT==== 26-Oct-2016::13:34:57 ===
  Error in process &lt;0.375.0&gt; with exit value:
  {badarg,[{project4,client,3,
                     [{file,"/Users/owner/Desktop/bank.erl"},
                      {line,27}]}]}
  
  =ERROR REPORT==== 26-Oct-2016::13:34:58 ===
  Error in process &lt;0.377.0&gt; with exit value:
  {badarg,[{project4,client,3,
                     [{file,"/Users/owner/Desktop/bank.erl"},
                      {line,27}]}]}
  &lt;0.378.0&gt; Balance request: 54&gt; 
  =ERROR REPORT==== 26-Oct-2016::13:34:58 ===
  Error in process &lt;0.378.0&gt; with exit value:
  {badarg,[{project4,client,3,
                     [{file,"/Users/owner/Desktop/bank.erl"},
                      {line,39}]}]}
  &lt;0.372.0&gt; Balance request: 54&gt; 
  =ERROR REPORT==== 26-Oct-2016::13:34:58 ===
  Error in process &lt;0.372.0&gt; with exit value:
  {badarg,[{project4,client,3,
                     [{file,"/Users/owner/Desktop/bank.erl"},
                      {line,39}]}]}
  </code></pre>
  
  <p>The code for the simulation is here: </p>
  
  <pre><code>-module(bankSim).
  -export([start/0, negativeOrPositive/0, sleep/1, generate_rand_int_list/3, generate_rand/2, client/3, clientSpawn/2, bank/2]).
  
  negativeOrPositive() -&gt; 
      M = rand:uniform(),
      if
          M =&lt; 0.5 -&gt; 
              1;
          true -&gt; 
              -1
      end.
  
  sleep(T) -&gt;
      receive
          after T -&gt; ok
      end.
  
  generate_rand_int_list(N,StartVal,Lim) -&gt;
      lists:map(fun (_) -&gt; (rand:uniform(Lim-StartVal) + StartVal)* negativeOrPositive() end, lists:seq(1,N)).
  
  generate_rand(StartVal, Lim) -&gt;
      rand:uniform(Lim-StartVal) + StartVal.
  
  client([], _ , BankID) -&gt;
      BankID ! {goodbye};
  client([H|T], Count, BankID) -&gt;
      BankID ! {transaction, self(), H},
      receive
          {Amount, Balance, Success} -&gt;
              io:format("Client: ~w, Amount requested: ~w, Bank Balance: ~w, Transaction successful ~w ~n",[self(), Amount, Balance, Success]);
          { X } -&gt;
              io:format("The balance is ~w ~n", [X])
      end,    
      sleep(generate_rand(500, 1500)),
      Mod = Count rem 5,
      if 
          Mod == 0 -&gt; 
              io:format("~w Balance request: ",[ self() ]),
              BankID! {balance, self()};
          true -&gt; 
              ok
      end,
      client(T, Count + 1, BankID).
  
  clientSpawn(0, _) -&gt;
          io:format("Finished spawning clients ~n",[]);
  clientSpawn(N, BankID) -&gt; 
          spawn(bankSim, client, [ generate_rand_int_list( generate_rand(10, 20), 0, 100) , 1, BankID] ),
          clientSpawn(N-1, BankID).
  
  
  bank(Balance, 0) -&gt;
      io:format("Banking simulation ended with a final balance of ~w ~n", [Balance]),
      io:format("simulation completed ~n", []);
  bank(Balance, NumClients) -&gt;
      receive
          {balance, Client} -&gt;
              Client ! {Balance};
          {transaction, Client, Amount} -&gt;
              NewBalance = Balance + Amount,
              if 
                  NewBalance =&lt; 0 -&gt;
                      Client ! {Amount, NewBalance, no},
                      bank(Balance, NumClients);
                  NewBalance &gt; 0 -&gt;
                      Client ! {Amount, NewBalance, yes},
                      bank(NewBalance, NumClients);
                  true -&gt; 
                      io:format("This will never be printed")
              end;
          goodbye -&gt;
              NewNumClients = NumClients - 1,
              bank(Balance, NewNumClients)
      end.
  
  
  start()-&gt;
      N = generate_rand(2,10),
      register(bank ,spawn(bankSim, bank, [generate_rand(2000,3000), N])),
      clientSpawn(N,bank).
  </code></pre>
  
  <p>Any help would be appreciated. </p>