avatarBirat Rai

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1614

Abstract

rly they propagate to application crashes.</p><div id="9259"><pre><span class="hljs-keyword">ERROR: </span>NullPointerException encountered while trying to adding String to Deque that is set to null. java.lang.NullPointerException Null Pointer Exception</pre></div><ul><li><b><i>Business Exception</i></b></li></ul><p id="2f3c">These are the events which were put in place because of business rules. They prevent the users from using the application.</p><div id="2b84"><pre>Logon failure: <span class="hljs-type">unknown</span> <span class="hljs-keyword">user</span> <span class="hljs-type">name</span> <span class="hljs-keyword">or</span> bad <span class="hljs-keyword">password</span> // This may be because <span class="hljs-keyword">of</span> <span class="hljs-keyword">user</span> <span class="hljs-type">name</span> <span class="hljs-type">unknown</span> <span class="hljs-keyword">or</span> wrong <span class="hljs-keyword">password</span></pre></div><div id="3970"><pre>Insufficient Funds: cannot <span class="hljs-built_in">make</span> transaction <span class="hljs-comment">// This may be because user doesn't have enough fund in their account</span></pre></div><blockquote id="c013"><p><b>Handling Exceptions?</b></p></blockquote><p id="b68d">Technical and Business Exceptions should be handled separately.</p><p id="64c5">It will create a potential source of confusion if we represent them within the same hierarchy.</p><p id="f99f">We should make it clear, what conditions it is required to ensure before calling, and what situations it is supposed to handle.</p><p id="35d6">Separating these two will

Options

give clarity and increases chances that technical exceptions are handled subtly by application framework (exception handling libraries), while business domain exceptions are handled by the client code.</p><figure id="adf7"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*mGeh1FCgI0bL2kKJz_rBgw.jpeg"><figcaption></figcaption></figure><p id="028f" type="7">TL;DR Understand the exceptions in your application. Do not mix Business Exception with Technical ones.</p><p id="bbc3"><a href="https://readmedium.com/97-journey-every-programmer-should-accomplish-a0c53dbbfd47"><i>Go to the series</i></a>.</p><p id="2f51">Go to <a href="https://readmedium.com/step-20-deploy-early-and-often-steve-berczuk-4d5d9099f0f5"><b><i>Twentieth Step</i></b></a></p><p id="7107">Go to the <a href="https://readmedium.com/step-22-do-lots-of-deliberate-practice-jon-jagger-663d93d27553"><b>22nd path</b></a>.</p><blockquote id="ba78"><p><b>References:</b></p></blockquote><ul><li><a href="https://www.gitbook.com/book/97-things-every-x-should-know/97-things-every-programmer-should-know/details"><i>97 things Every Programmer Should Know</i></a> ~ Git Book</li><li><a href="https://www.amazon.com/Things-Every-Programmer-Should-Know/dp/0596809484"><i>97 Things Every Programmer Should Know</i></a> ~ Paperback</li><li><a href="https://en.wikipedia.org/wiki/Exception_handling"><i>Technical Exceptions handling</i></a> ~ Wiki</li><li><a href="https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare"><i>Null pointer the billion dollar mistake</i></a> ~ Blog</li></ul></article></body>

Step 21: Distinguish Business Exceptions from Technical ~ Dan Bergh Johnsson

This is the 21st Step towards gaining the Programming Enlightenment series. If you didn’t learn the Twentieth Step, read it.

“I call it my billion-dollar mistake. It was the invention of the null reference in 1965.”

~ Tony Hoare

Equally Good API isn’t built right the first time. Even more, it’s difficult to change it later. Don’t even put into the picture the pain to support for the API changes.

What is an Exception?

An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions

What are the types of Exception?

We can classify Exception into two types.

  • Technical Exception

These can be termed as events which go wrong because of technical errors. If not handled properly they propagate to application crashes.

ERROR: NullPointerException encountered while trying to adding String to Deque that is set to null.
java.lang.NullPointerException
Null Pointer Exception
  • Business Exception

These are the events which were put in place because of business rules. They prevent the users from using the application.

Logon failure: unknown user name or bad password
// This may be because of user name unknown or wrong password
Insufficient Funds: cannot make transaction
// This may be because user doesn't have enough fund in their account

Handling Exceptions?

Technical and Business Exceptions should be handled separately.

It will create a potential source of confusion if we represent them within the same hierarchy.

We should make it clear, what conditions it is required to ensure before calling, and what situations it is supposed to handle.

Separating these two will give clarity and increases chances that technical exceptions are handled subtly by application framework (exception handling libraries), while business domain exceptions are handled by the client code.

TL;DR Understand the exceptions in your application. Do not mix Business Exception with Technical ones.

Go to the series.

Go to Twentieth Step

Go to the 22nd path.

References:

Programming
Software Development
Android
Java
Coding
Recommended from ReadMedium