title: Erlang 'catch' expression vs try/catch in terms of efficiency
body: <p>A similar question was asked about this but it was not exactly asked in the same terms.</p>
  
  <p>I am trying to safely decode base64 binaries, in a context where it's possible the input will not be a binary, or even base64 encoded.</p>
  
  <p>Erlang says let it crash and handle it -- if I were to do this, what is the most efficient way. Efficiency is quite important in this system.</p>
  
  <p>I know to avoid try/catch, as it builds a full stack trace -- however, is the catch keyword reasonable for this context? And is the catch keyword faster/more efficient?</p>
  
  <p>In a function such as </p>
  
  <pre><code>safe_decode(Binary) -&gt;
      case catch base64:decode(Binary) of
          &lt;&lt;Result/binary&gt;&gt; -&gt; {ok, Result};
          {'EXIT', _} -&gt; {not_base64, Binary}
      end.
  </code></pre>
  
  <p>Is this truly more efficient than a try catch? How best to handle this scenario in a system where efficiency is important i.e. crashes which involve building a stack trace and/or require more processing than the happy path need to be handled as efficiently as possible.</p>
  
  <p>I'm just learning erlang, so maybe the answer is staring me in the face.</p>