<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;action=history&amp;feed=atom</id>
		<title>Distinguish Business Exceptions from Technical - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;action=history&amp;feed=atom"/>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;action=history"/>
		<updated>2013-05-26T02:58:06Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.11.0</generator>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24948&amp;oldid=prev</id>
		<title>Kevlin at 08:46, 19 July 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24948&amp;oldid=prev"/>
				<updated>2009-07-19T08:46:16Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 08:46, 19 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong at runtime: technical problems that prevent us from using the application and business logic that prevents us from misusing the application. Most modern languages, such as LISP, Java, Smalltalk, and C#, use exceptions to signal both these situations. However, the two situations are so different that they should be carefully held apart. It is a potential source of confusion to represent them both using the same exception hierarchy, not to mention the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong at runtime: technical problems that prevent us from using the application and business logic that prevents us from misusing the application. Most modern languages, such as LISP, Java, Smalltalk, and C#, use exceptions to signal both these situations. However, the two situations are so different that they should be carefully held apart. It is a potential source of confusion to represent them both using the same exception hierarchy, not to mention the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;An &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;unresovable &lt;/del&gt;technical problem can occur when there is a programming error. For example, if you try to access element 83 from an array of size 17, then the program is clearly off track, and some exception &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;will &lt;/del&gt;result. The subtler version is calling some library code with inappropriate arguments, causing the same situation on the inside of the library.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;An &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;unresolvable &lt;/ins&gt;technical problem can occur when there is a programming error. For example, if you try to access element 83 from an array of size 17, then the program is clearly off track, and some exception &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;should &lt;/ins&gt;result. The subtler version is calling some library code with inappropriate arguments, causing the same situation on the inside of the library.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It would be a mistake to attempt to resolve these situations you caused yourself. Instead we let the exception bubble up to the highest architectural level and let some general exception handling mechanism do what it can to ensure the system is in a safe state, such as rolling back a transaction, logging and alerting administration, and reporting back (politely) to the user. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It would be a mistake to attempt to resolve these situations you caused yourself. Instead we let the exception bubble up to the highest architectural level and let some general exception&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/ins&gt;handling mechanism do what it can to ensure the system is in a safe state, such as rolling back a transaction, logging and alerting administration, and reporting back (politely) to the user. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are in the &amp;quot;library situation&amp;quot; and a &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;call &lt;/del&gt;has broken the contract of your method, e g passing a totally bizarre argument or not having &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;set up &lt;/del&gt;a dependent object properly. This is on a par with accessing 83rd element from 17&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;; &lt;/del&gt;the caller should have checked; not doing so is a programmer error on the client side. The proper response is to throw a technical exception.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;''&lt;/ins&gt;you&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;'' &lt;/ins&gt;are in the &amp;quot;library situation&amp;quot; and a &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;caller &lt;/ins&gt;has broken the contract of your method, e&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/ins&gt;g&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;., &lt;/ins&gt;passing a totally bizarre argument or not having a dependent object &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;set up &lt;/ins&gt;properly. This is on a par with accessing 83rd element from 17&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;: &lt;/ins&gt;the caller should have checked; not doing so is a programmer error on the client side. The proper response is to throw a technical exception.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A different, but still technical, situation is when the program cannot proceed because of a problem in the execution environment, such as an unresponsive database. In this situation you must assume that the infrastructure &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;has done &lt;/del&gt;what it &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;can to try &lt;/del&gt;to resolve the situation&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, e.g., &lt;/del&gt;repairing connections and retrying a reasonable number of times. Even if the cause is different, the situation for the calling code is similar: there is little it can do about it. So, we signal the situation through an exception that we let bubble up to the general exception handling mechanism.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A different, but still technical, situation is when the program cannot proceed because of a problem in the execution environment, such as an unresponsive database. In this situation you must assume that the infrastructure &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;did &lt;/ins&gt;what it &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;could &lt;/ins&gt;to resolve the situation &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;mdash; &lt;/ins&gt;repairing connections and retrying a reasonable number of times &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;mdash; and failed&lt;/ins&gt;. Even if the cause is different, the situation for the calling code is similar: there is little it can do about it. So, we signal the situation through an exception that we let bubble up to the general exception handling mechanism.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In contrast to these, we have the situation where you cannot complete the call for a domain-logical reason. In this case we have encountered a situation that is an exception, i.e., unusual and undesirable, but not bizarre or programmatically in error. For example, if I try to withdraw money from an account with insufficient funds. In other words, this kind of situation is a part of the contract, and throwing an exception is just an ''alternative return path'' that is part of the model and that the client should be aware of and be prepared to handle. For these situations it is appropriate to create a specific exception or a separate exception hierarchy so that the client can handle the situation on its own terms.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In contrast to these, we have the situation where you cannot complete the call for a domain-logical reason. In this case we have encountered a situation that is an exception, i.e., unusual and undesirable, but not bizarre or programmatically in error. For example, if I try to withdraw money from an account with insufficient funds. In other words, this kind of situation is a part of the contract, and throwing an exception is just an ''alternative return path'' that is part of the model and that the client should be aware of and be prepared to handle. For these situations it is appropriate to create a specific exception or a separate exception hierarchy so that the client can handle the situation on its own terms.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:24947:newid:24948 --&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24947&amp;oldid=prev</id>
		<title>Danbj: reworking tech exception part, shortening it slightly</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24947&amp;oldid=prev"/>
				<updated>2009-07-19T08:23:05Z</updated>
		
		<summary type="html">&lt;p&gt;reworking tech exception part, shortening it slightly&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 08:23, 19 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong at runtime: technical problems that prevent us from using the application and business logic that prevents us from misusing the application. Most modern languages, such as LISP, Java, Smalltalk, and C#, use exceptions to signal both these situations. However, the two situations are so different that they should be carefully held apart. It is a potential source of confusion to represent them both using the same exception hierarchy, not to mention the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong at runtime: technical problems that prevent us from using the application and business logic that prevents us from misusing the application. Most modern languages, such as LISP, Java, Smalltalk, and C#, use exceptions to signal both these situations. However, the two situations are so different that they should be carefully held apart. It is a potential source of confusion to represent them both using the same exception hierarchy, not to mention the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;When an unresolvable &lt;/del&gt;technical problem &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;occurs, &lt;/del&gt;there is &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;usually not much the calling client code can do about it&lt;/del&gt;. For example, if you &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;make a call to some library code resulting in an attempt &lt;/del&gt;to access &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;array &lt;/del&gt;element 83 from an array of size 17, then the program is clearly off track &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;mdash; if you knew the array was too small&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;you wouldn't have made call in the first place&lt;/del&gt;. The library code &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;will respond by throwing some kind &lt;/del&gt;of &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;index-out-of-bound exception&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;An unresovable &lt;/ins&gt;technical problem &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;can occur when &lt;/ins&gt;there is &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a programming error&lt;/ins&gt;. For example, if you &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;try &lt;/ins&gt;to access element 83 from an array of size 17, then the program is clearly off track, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;and some exception will result&lt;/ins&gt;. The &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;subtler version is calling some &lt;/ins&gt;library code &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;with inappropriate arguments, causing the same situation on the inside &lt;/ins&gt;of &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the library&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It would be a mistake to attempt to resolve these situations you caused yourself. Instead we let the exception bubble up to the highest architectural level and some general exception handling mechanism do what it can to ensure the system is in a safe state, such as rolling back a transaction, logging and alerting administration, and reporting back (politely) to the user. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It would be a mistake to attempt to resolve these situations you caused yourself. Instead we let the exception bubble up to the highest architectural level and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;let &lt;/ins&gt;some general exception handling mechanism do what it can to ensure the system is in a safe state, such as rolling back a transaction, logging and alerting administration, and reporting back (politely) to the user. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are in the &amp;quot;library situation&amp;quot; and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;realize &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;client calling &lt;/del&gt;your &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;code has made a mistake &lt;/del&gt;e g passing a totally bizarre argument or not having set up a dependent object properly. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Such code defects are &lt;/del&gt;on a par with &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;trying to get the &lt;/del&gt;83rd element from 17&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. The &lt;/del&gt;caller should have checked; not doing so is &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a breach of your method's contract and &lt;/del&gt;a programmer error on the client side. The proper response is to throw &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;an illegal-argument or illegal-state &lt;/del&gt;exception.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are in the &amp;quot;library situation&amp;quot; and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a call has broken &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;contract of &lt;/ins&gt;your &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;method, &lt;/ins&gt;e g passing a totally bizarre argument or not having set up a dependent object properly. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;This is &lt;/ins&gt;on a par with &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;accessing &lt;/ins&gt;83rd element from 17&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;; the &lt;/ins&gt;caller should have checked; not doing so is a programmer error on the client side. The proper response is to throw &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a technical &lt;/ins&gt;exception.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A different, but still technical, situation is when the program cannot proceed because of a problem in the execution environment, such as an unresponsive database. In this situation you must assume that the infrastructure has done what it can to try to resolve the situation, e.g., repairing connections and retrying a reasonable number of times. Even if the cause is different, the situation for the calling code is similar: there is little it can do about it. So, we signal the situation through an exception that we let bubble up to the general exception handling mechanism.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A different, but still technical, situation is when the program cannot proceed because of a problem in the execution environment, such as an unresponsive database. In this situation you must assume that the infrastructure has done what it can to try to resolve the situation, e.g., repairing connections and retrying a reasonable number of times. Even if the cause is different, the situation for the calling code is similar: there is little it can do about it. So, we signal the situation through an exception that we let bubble up to the general exception handling mechanism.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Danbj</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24943&amp;oldid=prev</id>
		<title>Danbj: removing double whitespace</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24943&amp;oldid=prev"/>
				<updated>2009-07-19T06:38:07Z</updated>
		
		<summary type="html">&lt;p&gt;removing double whitespace&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 06:38, 19 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It would be a mistake to attempt to resolve these situations you caused yourself. Instead we let the exception bubble up to the highest architectural level and some general exception handling mechanism do what it can to ensure the system is in a safe state, such as rolling back a transaction, logging and alerting administration, and reporting back (politely) to the user. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It would be a mistake to attempt to resolve these situations you caused yourself. Instead we let the exception bubble up to the highest architectural level and some general exception handling mechanism do what it can to ensure the system is in a safe state, such as rolling back a transaction, logging and alerting administration, and reporting back (politely) to the user. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are in the &amp;quot;library situation&amp;quot; and realize the client calling your code has made a mistake e g passing a totally bizarre argument or not having set up a dependent object properly. Such code defects are on a par with trying to get the 83rd element from 17. The caller should have checked; not doing so is a breach of your method's contract and a programmer error on the client side. The proper response is to throw an illegal-argument or illegal-state exception.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are in the &amp;quot;library situation&amp;quot; and realize the client calling your code has made a mistake e g passing a totally bizarre argument or not having set up a dependent object properly. Such code defects are on a par with trying to get the 83rd element from 17. The caller should have checked; not doing so is a breach of your method's contract and a programmer error on the client side. The proper response is to throw an illegal-argument or illegal-state exception.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Danbj</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24942&amp;oldid=prev</id>
		<title>Danbj: cutting down a little</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24942&amp;oldid=prev"/>
				<updated>2009-07-19T06:37:18Z</updated>
		
		<summary type="html">&lt;p&gt;cutting down a little&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 06:37, 19 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are in the &amp;quot;library situation&amp;quot; and realize the client calling your code has made a mistake &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;mdash; your method might have been called with &lt;/del&gt;a totally bizarre argument or &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a dependent object has &lt;/del&gt;not &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;been &lt;/del&gt;set up properly. Such code defects are on a par with trying to get the 83rd element from 17. The caller should have checked; not doing so is a breach of your method's contract and a programmer error on the client side. The proper response is to throw an illegal-argument or illegal-state exception.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are in the &amp;quot;library situation&amp;quot; and realize the client calling your code has made a mistake &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;e g passing &lt;/ins&gt;a totally bizarre argument or not &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;having &lt;/ins&gt;set up &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a dependent object &lt;/ins&gt;properly. Such code defects are on a par with trying to get the 83rd element from 17. The caller should have checked; not doing so is a breach of your method's contract and a programmer error on the client side. The proper response is to throw an illegal-argument or illegal-state exception.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A different, but still technical, situation is when the program cannot proceed because of a problem in the execution environment, such as an unresponsive database. In this situation you must assume that the infrastructure has done what it can to try to resolve the situation, e.g., repairing connections and retrying a reasonable number of times. Even if the cause is different, the situation for the calling code is similar: there is little it can do about it. So, we signal the situation through an exception that we let bubble up to the general exception handling mechanism.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A different, but still technical, situation is when the program cannot proceed because of a problem in the execution environment, such as an unresponsive database. In this situation you must assume that the infrastructure has done what it can to try to resolve the situation, e.g., repairing connections and retrying a reasonable number of times. Even if the cause is different, the situation for the calling code is similar: there is little it can do about it. So, we signal the situation through an exception that we let bubble up to the general exception handling mechanism.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Danbj</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24941&amp;oldid=prev</id>
		<title>Danbj: cutting down a little</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24941&amp;oldid=prev"/>
				<updated>2009-07-19T06:34:15Z</updated>
		
		<summary type="html">&lt;p&gt;cutting down a little&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 06:34, 19 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong at runtime: technical problems that prevent us from using the application and business logic that prevents us from misusing the application. Most modern languages, such as LISP, Java, Smalltalk, and C#, use exceptions to signal both these situations. However, the two situations are so different that they should be carefully held apart. It is a potential source of confusion to represent them both using the same exception hierarchy, not to mention the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong at runtime: technical problems that prevent us from using the application and business logic that prevents us from misusing the application. Most modern languages, such as LISP, Java, Smalltalk, and C#, use exceptions to signal both these situations. However, the two situations are so different that they should be carefully held apart. It is a potential source of confusion to represent them both using the same exception hierarchy, not to mention the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;When an unresolvable technical problem occurs, there is usually not much the calling client code can do about it. For example, if you make a call to some library code resulting in an attempt to access array element 83 from an array of size 17, then the program is clearly off track &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;and the library code will throw some kind of index-out-of-bound exception. As a client there's not much that can be done with these kinds of exceptions at runtime &lt;/del&gt;&amp;amp;mdash; if you knew the array was too small, you wouldn't have made call in the first place.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;When an unresolvable technical problem occurs, there is usually not much the calling client code can do about it. For example, if you make a call to some library code resulting in an attempt to access array element 83 from an array of size 17, then the program is clearly off track &amp;amp;mdash; if you knew the array was too small, you wouldn't have made call in the first place&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. The library code will respond by throwing some kind of index-out-of-bound exception.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;It would be a mistake to attempt to resolve these situations you caused yourself. Instead we let the exception bubble up to the highest architectural level and some general exception handling mechanism do what it can to ensure the system is in a safe state, such as rolling back a transaction, logging and alerting administration, and reporting back (politely) to the user&lt;/ins&gt;. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Instead of catching and handling unresolvable situations, we probably let the exception bubble up to the highest architectural level and let some general exception handling mechanism do what it can to ensure the system is in a safe state, such as rolling back a transaction, logging and alerting administration, and reporting back (politely) to the user.&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are in the &amp;quot;library situation&amp;quot; and realize the client calling your code has made a mistake &amp;amp;mdash; your method might have been called with a totally bizarre argument or a dependent object has not been set up properly. Such code defects are on a par with trying to get the 83rd element from 17. The caller should have checked; not doing so is a breach of your method's contract and a programmer error on the client side. The proper response is to throw an illegal-argument or illegal-state exception.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are in the &amp;quot;library situation&amp;quot; and realize the client calling your code has made a mistake &amp;amp;mdash; your method might have been called with a totally bizarre argument or a dependent object has not been set up properly. Such code defects are on a par with trying to get the 83rd element from 17. The caller should have checked; not doing so is a breach of your method's contract and a programmer error on the client side. The proper response is to throw an illegal-argument or illegal-state exception.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:24761:newid:24941 --&gt;
&lt;/table&gt;</summary>
		<author><name>Danbj</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24761&amp;oldid=prev</id>
		<title>Kevlin at 22:17, 9 July 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=24761&amp;oldid=prev"/>
				<updated>2009-07-09T22:17:45Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 22:17, 9 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong at runtime&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. Either there is some &lt;/del&gt;technical &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;problem or there is some reason related to &lt;/del&gt;business logic that &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;we cannot proceed&lt;/del&gt;. Most modern languages, such as LISP, Java, Smalltalk, and C#, use exceptions to signal both these situations. However, the two situations are so different that they should be carefully held apart. It is a potential source of confusion to represent them both using the same exception hierarchy, not to mention the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong at runtime&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;: &lt;/ins&gt;technical &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;problems that prevent us from using the application and &lt;/ins&gt;business logic that &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;prevents us from misusing the application&lt;/ins&gt;. Most modern languages, such as LISP, Java, Smalltalk, and C#, use exceptions to signal both these situations. However, the two situations are so different that they should be carefully held apart. It is a potential source of confusion to represent them both using the same exception hierarchy, not to mention the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;When an &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;irresolvable &lt;/del&gt;technical problem occurs, there is usually not much the calling client code can do about it. For example, if you make a call to some library code resulting in an attempt to access array element 83 from an array of size 17, then the program is clearly off track and the library code will throw some kind of index-out-of-bound exception. As a client there's not much that can be done with these kinds of exceptions at runtime &amp;amp;mdash; if you knew the array was too small, you wouldn't have made call in the first place.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;When an &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;unresolvable &lt;/ins&gt;technical problem occurs, there is usually not much the calling client code can do about it. For example, if you make a call to some library code resulting in an attempt to access array element 83 from an array of size 17, then the program is clearly off track and the library code will throw some kind of index-out-of-bound exception. As a client there's not much that can be done with these kinds of exceptions at runtime &amp;amp;mdash; if you knew the array was too small, you wouldn't have made call in the first place.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Instead of catching and handling &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;irresolvable &lt;/del&gt;situations, we probably let the exception bubble up to the highest architectural level and let some general exception handling mechanism do what it can to ensure the system is in a safe state, such as rolling back a transaction, logging and alerting administration, and reporting to the user &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;in some polite manner&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Instead of catching and handling &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;unresolvable &lt;/ins&gt;situations, we probably let the exception bubble up to the highest architectural level and let some general exception handling mechanism do what it can to ensure the system is in a safe state, such as rolling back a transaction, logging and alerting administration, and reporting &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;back (politely) &lt;/ins&gt;to the user.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;sitting &lt;/del&gt;in the &amp;quot;library situation&amp;quot; and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;realise that &lt;/del&gt;the client calling your code has made a mistake&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. E.g., &lt;/del&gt;your method might have been called with a totally bizarre argument&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/del&gt;or &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the caller might have not made the proper setup of &lt;/del&gt;a dependent object. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;This is a &lt;/del&gt;code &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;defect &lt;/del&gt;on a par with trying to get the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;83th &lt;/del&gt;element from 17. The caller should have checked&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, and &lt;/del&gt;not doing so is a breach of your method's contract and a programmer error on the client side. The proper response is to throw an illegal-argument or illegal-state exception.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are in the &amp;quot;library situation&amp;quot; and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;realize &lt;/ins&gt;the client calling your code has made a mistake &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;mdash; &lt;/ins&gt;your method might have been called with a totally bizarre argument or a dependent object &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;has not been set up properly&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Such &lt;/ins&gt;code &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;defects are &lt;/ins&gt;on a par with trying to get the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;83rd &lt;/ins&gt;element from 17. The caller should have checked&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;; &lt;/ins&gt;not doing so is a breach of your method's contract and a programmer error on the client side. The proper response is to throw an illegal-argument or illegal-state exception.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A different, but still technical, situation is when the program cannot proceed &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;due to some deficiency &lt;/del&gt;in the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;runtime &lt;/del&gt;environment, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for example, if a necessary &lt;/del&gt;database &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;does not respond&lt;/del&gt;. In this situation you must assume that the infrastructure has done what it can to try to resolve the situation, e.g., repairing connections and retrying a reasonable number of times. Even if the cause is different, the situation for the calling code is similar: there is little it can do about it. So, we signal the situation through an exception that we let bubble up to the general exception handling mechanism.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A different, but still technical, situation is when the program cannot proceed &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;because of a problem &lt;/ins&gt;in the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;execution &lt;/ins&gt;environment, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;such as an unresponsive &lt;/ins&gt;database. In this situation you must assume that the infrastructure has done what it can to try to resolve the situation, e.g., repairing connections and retrying a reasonable number of times. Even if the cause is different, the situation for the calling code is similar: there is little it can do about it. So, we signal the situation through an exception that we let bubble up to the general exception handling mechanism.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In contrast to these, we have the situation where you cannot complete the call for a domain-logical reason. In this case we have encountered a situation that is an exception, i.e., unusual and undesirable, but not bizarre or programmatically in error. For example, if I try to withdraw money from an account with insufficient funds. In other words, this kind of situation is a part of the contract, and throwing an exception is just an ''alternative return path'' that is part of the model and that the client should be aware of&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, take into account, &lt;/del&gt;and be prepared to handle. For these situations it is &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;suitable and advisable &lt;/del&gt;to create a specific exception or a separate exception hierarchy so that the client can &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;precisely catch and &lt;/del&gt;handle the situation.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In contrast to these, we have the situation where you cannot complete the call for a domain-logical reason. In this case we have encountered a situation that is an exception, i.e., unusual and undesirable, but not bizarre or programmatically in error. For example, if I try to withdraw money from an account with insufficient funds. In other words, this kind of situation is a part of the contract, and throwing an exception is just an ''alternative return path'' that is part of the model and that the client should be aware of and be prepared to handle. For these situations it is &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;appropriate &lt;/ins&gt;to create a specific exception or a separate exception hierarchy so that the client can handle the situation &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;on its own terms&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Mixing technical exceptions and business exceptions in the same hierarchy blurs the distinction and confuses the caller about what the method contract is, what conditions it is required to ensure before calling, and what situations it is supposed to handle. Separating the cases gives clarity and increases the chances that technical exceptions will be handled by some application framework, while the business domain &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;exceptional situations &lt;/del&gt;actually are considered and handled by the client code.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Mixing technical exceptions and business exceptions in the same hierarchy blurs the distinction and confuses the caller about what the method contract is, what conditions it is required to ensure before calling, and what situations it is supposed to handle. Separating the cases gives clarity and increases the chances that technical exceptions will be handled by some application framework, while the business domain &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;exceptions &lt;/ins&gt;actually are considered and handled by the client code.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[Dan Bergh Johnsson]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[Dan Bergh Johnsson]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=21895&amp;oldid=prev</id>
		<title>Kevlin at 06:42, 5 December 2008</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=21895&amp;oldid=prev"/>
				<updated>2008-12-05T06:42:18Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 06:42, 5 December 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;during &lt;/del&gt;runtime. Either there is some technical problem or there is some &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;business logical &lt;/del&gt;reason that we cannot proceed. Most modern languages such as LISP, Java, Smalltalk, and C# use exceptions to signal both these situations. However, the two situations are so different that they should be carefully held apart. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;As a contrast, it &lt;/del&gt;is &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for example &lt;/del&gt;a &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;dangerous &lt;/del&gt;source &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for &lt;/del&gt;confusion &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;by representing &lt;/del&gt;them both using the same exception hierarchy, not to mention &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;using &lt;/del&gt;the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;at &lt;/ins&gt;runtime. Either there is some technical problem or there is some reason &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;related to business logic &lt;/ins&gt;that we cannot proceed. Most modern languages&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;such as LISP, Java, Smalltalk, and C#&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;use exceptions to signal both these situations. However, the two situations are so different that they should be carefully held apart. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;It &lt;/ins&gt;is a &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;potential &lt;/ins&gt;source &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;of &lt;/ins&gt;confusion &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;to represent &lt;/ins&gt;them both using the same exception hierarchy, not to mention the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;When an irresolvable technical problem occurs, there is usually not much the calling client code can do about it. For example, if you make a call to some library code resulting in an attempt to access array element 83 from an array of size 17, then the program is clearly off track and the library code will throw some kind of &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;array-&lt;/del&gt;index-out-of-bound exception. As a client there &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is &lt;/del&gt;not much &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;idea of catching &lt;/del&gt;these kinds of exceptions &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;– &lt;/del&gt;if you knew the array was too small, you &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;wouldn’t &lt;/del&gt;have made call in the first place.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;When an irresolvable technical problem occurs, there is usually not much the calling client code can do about it. For example, if you make a call to some library code resulting in an attempt to access array element 83 from an array of size 17, then the program is clearly off track and the library code will throw some kind of index-out-of-bound exception. As a client there&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;'s &lt;/ins&gt;not much &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that can be done with &lt;/ins&gt;these kinds of exceptions &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;at runtime &amp;amp;mdash; &lt;/ins&gt;if you knew the array was too small, you &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;wouldn't &lt;/ins&gt;have made call in the first place.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Instead of catching and handling irresolvable situations, we probably let the exception bubble up to the highest architectural level and let some general exception handling mechanism do what it can to ensure the system is in a safe state &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;(ensuring &lt;/del&gt;transaction &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;rollback et al)&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;log &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;alert &lt;/del&gt;administration, and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;report &lt;/del&gt;to the user in some &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;neat way&lt;/del&gt;. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Instead of catching and handling irresolvable situations, we probably let the exception bubble up to the highest architectural level and let some general exception handling mechanism do what it can to ensure the system is in a safe state&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, such as rolling back a &lt;/ins&gt;transaction, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;logging &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;alerting &lt;/ins&gt;administration, and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;reporting &lt;/ins&gt;to the user in some &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;polite manner&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are sitting in the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;“library situation” &lt;/del&gt;and realise that the client calling your code has made a mistake. E g your method might have been called with a totally bizarre argument, or the caller might have not made the proper setup of a dependent object. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Actually, this &lt;/del&gt;is a code defect &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;as bad as &lt;/del&gt;trying to get the 83th element &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;out of &lt;/del&gt;17. The caller should have checked, and not doing so is a breach &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;against the contract &lt;/del&gt;of your method and a programmer error on the client side. The proper response is &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;throwing some exceptions, e g &lt;/del&gt;illegal-argument&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-exception &lt;/del&gt;or illegal-state&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/del&gt;exception.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of this situation is when you are sitting in the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;quot;library situation&amp;quot; &lt;/ins&gt;and realise that the client calling your code has made a mistake. E&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/ins&gt;g&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;., &lt;/ins&gt;your method might have been called with a totally bizarre argument, or the caller might have not made the proper setup of a dependent object. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;This &lt;/ins&gt;is a code defect &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;on a par with &lt;/ins&gt;trying to get the 83th element &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;from &lt;/ins&gt;17. The caller should have checked, and not doing so is a breach of your method&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;'s contract &lt;/ins&gt;and a programmer error on the client side. The proper response is &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;to throw an &lt;/ins&gt;illegal-argument or illegal-state exception.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A different, but still technical, situation is when the program cannot proceed due to some deficiency in the runtime environment, for example if a necessary database does not respond. In this situation you must assume that the infrastructure has done what it can to try to resolve the situation, e g repairing connections and retrying a &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;fair amount &lt;/del&gt;of times. Even if the cause is different, the situation for the code is similar: there is &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;nothing to &lt;/del&gt;do about it. So, we signal the situation through an exception that we let bubble up to the general exception handling mechanism&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. This is also the behaviour seen in several frameworks such as Spring or Hibernate&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A different, but still technical, situation is when the program cannot proceed due to some deficiency in the runtime environment, for example&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;if a necessary database does not respond. In this situation you must assume that the infrastructure has done what it can to try to resolve the situation, e&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/ins&gt;g&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;., &lt;/ins&gt;repairing connections and retrying a &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;reasonable number &lt;/ins&gt;of times. Even if the cause is different, the situation for the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;calling &lt;/ins&gt;code is similar: there is &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;little it can &lt;/ins&gt;do about it. So, we signal the situation through an exception that we let bubble up to the general exception handling mechanism.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;sharp &lt;/del&gt;contrast to these, we have the situation where you cannot complete the call for a domain logical reason. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt; &lt;/del&gt;In this case we have encountered a situation that is an exception, i e unusual, but not bizarre or &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;erroneous &lt;/del&gt;in &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;any way&lt;/del&gt;. For example, if I try to withdraw money from an &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;ATM but balance is not sufficient, it is an unusual situation but not un-normal&lt;/del&gt;. In other words this kind of situation is a part of the contract, and throwing an exception is just an &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;“alternative return” &lt;/del&gt;that is part of the model and that the client should &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;understand well&lt;/del&gt;, take into account, and be prepared to handle. For these situations it is suitable and advisable to create a specific exception or a separate exception hierarchy so that the client can precisely catch and handle the situation&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, e g insufficient-balance-exception. &lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In contrast to these, we have the situation where you cannot complete the call for a domain&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/ins&gt;logical reason. In this case we have encountered a situation that is an exception, i&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/ins&gt;e&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;., &lt;/ins&gt;unusual &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;and undesirable&lt;/ins&gt;, but not bizarre or &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;programmatically &lt;/ins&gt;in &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;error&lt;/ins&gt;. For example, if I try to withdraw money from an &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;account with insufficient funds&lt;/ins&gt;. In other words&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;this kind of situation is a part of the contract, and throwing an exception is just an &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;''alternative return path'' &lt;/ins&gt;that is part of the model and that the client should &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;be aware of&lt;/ins&gt;, take into account, and be prepared to handle. For these situations it is suitable and advisable to create a specific exception or a separate exception hierarchy so that the client can precisely catch and handle the situation.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Mixing technical exceptions and business exceptions in the same hierarchy blurs the distinction and confuses the caller about what the method contract is, what conditions it is required to ensure before calling and what situations it is supposed to handle. Separating the cases gives clarity and increases the chances that technical exceptions are let to be handled by some application framework, while the business domain model exceptional situations actually are considered and handled by the client code&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Mixing technical exceptions and business exceptions in the same hierarchy blurs the distinction and confuses the caller about what the method contract is, what conditions it is required to ensure before calling, and what situations it is supposed to handle. Separating the cases gives clarity and increases the chances that technical exceptions will be handled by some application framework, while the business domain exceptional situations actually are considered and handled by the client code.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[Dan Bergh Johnsson]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[Dan Bergh Johnsson]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:21823:newid:21895 --&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=21823&amp;oldid=prev</id>
		<title>Danbj: Edit after feedback - ended up longer ...</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=21823&amp;oldid=prev"/>
				<updated>2008-11-28T08:00:33Z</updated>
		
		<summary type="html">&lt;p&gt;Edit after feedback - ended up longer ...&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 08:00, 28 November 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong during runtime. Either there is some technical problem or there is some business logical reason that we cannot proceed. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Both of &lt;/del&gt;these &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;are &lt;/del&gt;situations &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;are usually signalled through exceptions&lt;/del&gt;. However, the situations are so different that they should be carefully held apart. As a contrast, it is for example a dangerous source for confusion by representing them both using the same exception hierarchy, not to mention using the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong during runtime. Either there is some technical problem or there is some business logical reason that we cannot proceed. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Most modern languages such as LISP, Java, Smalltalk, and C# use exceptions to signal both &lt;/ins&gt;these situations. However, the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;two &lt;/ins&gt;situations are so different that they should be carefully held apart. As a contrast, it is for example a dangerous source for confusion by representing them both using the same exception hierarchy, not to mention using the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;When an irresolvable technical problem occurs, there is usually not much the calling client code can do about it. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;If for &lt;/del&gt;example &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a necessary database does not respond&lt;/del&gt;, you &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;must assume that the infrastructure has done what it can &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;try &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;resolve &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;situation, e g repairing connections &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;retrying a fair amount &lt;/del&gt;of &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;times&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;So, as &lt;/del&gt;a client there is not much idea of catching &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;and handling &lt;/del&gt;these kinds of exceptions&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. Instead we probably let them bubble up to &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;highest architectural level and let some general exception handling mechanism do what it can to ensure the system is &lt;/del&gt;in &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a safe state (ensuring transaction rollback et al), log and alert administration, and report to &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;user in some neat way&lt;/del&gt;. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;When an irresolvable technical problem occurs, there is usually not much the calling client code can do about it. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;For &lt;/ins&gt;example, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;if &lt;/ins&gt;you &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;make a call &lt;/ins&gt;to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;some library code resulting in an attempt &lt;/ins&gt;to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;access array element 83 from an array of size 17, then &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;program is clearly off track &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the library code will throw some kind &lt;/ins&gt;of &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;array-index-out-of-bound exception&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;As &lt;/ins&gt;a client there is not much idea of catching these kinds of exceptions &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;– if you knew &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;array was too small, you wouldn’t have made call &lt;/ins&gt;in the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;first place&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Obviously exceptions signalling &lt;/del&gt;irresolvable &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;technical problems should be unchecked so that they transparently can “bubble through”. Some infrastructure APIs&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;e g “java.sql”, force their clients &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;catch &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;handle exceptions, and in that situation there is basically one reasonable thing &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;do – wrap &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;exception &lt;/del&gt;in &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;some unchecked exception&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;add contextual data&lt;/del&gt;, and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;re-throw &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;wrapped version. If you are &lt;/del&gt;in &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;an EJB container, then the EJBException (which extends RuntimeException) was created for precisely this reason, and other frameworks have a similar construct. In general decent choices could be IllegalStateException or RuntimeException itself&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Instead of catching and handling &lt;/ins&gt;irresolvable &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;situations&lt;/ins&gt;, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;we probably let the exception bubble up &lt;/ins&gt;to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the highest architectural level &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;let some general exception handling mechanism do what it can &lt;/ins&gt;to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;ensure &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;system is &lt;/ins&gt;in &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a safe state (ensuring transaction rollback et al)&lt;/ins&gt;, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;log and alert administration&lt;/ins&gt;, and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;report to &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;user &lt;/ins&gt;in &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;some neat way&lt;/ins&gt;. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;an irresolvable technical problem &lt;/del&gt;is &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;if &lt;/del&gt;you realise that the client calling your code has made a mistake. E g &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;you could realise that they &lt;/del&gt;have called &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;your method &lt;/del&gt;with a totally bizarre argument, or &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that they &lt;/del&gt;have not made the proper setup of a dependent object. Actually, this is as bad as trying to get the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;47th &lt;/del&gt;element out of &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;an array of length 32&lt;/del&gt;. The caller should have checked, and not doing so is a breach against the contract of your method and a programmer error on the client side. The proper response &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;again &lt;/del&gt;is throwing some &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;unchecked &lt;/del&gt;exceptions, e g &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;IllegalArgumentException &lt;/del&gt;or &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;IllegalStateException&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A variant of &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;this situation &lt;/ins&gt;is &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;when &lt;/ins&gt;you &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;are sitting in the “library situation” and &lt;/ins&gt;realise that the client calling your code has made a mistake. E g &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;your method might &lt;/ins&gt;have &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;been &lt;/ins&gt;called with a totally bizarre argument, or &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the caller might &lt;/ins&gt;have not made the proper setup of a dependent object. Actually, this is &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a code defect &lt;/ins&gt;as bad as trying to get the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;83th &lt;/ins&gt;element out of &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;17&lt;/ins&gt;. The caller should have checked, and not doing so is a breach against the contract of your method and a programmer error on the client side. The proper response is throwing some exceptions, e g &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;illegal-argument-exception &lt;/ins&gt;or &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;illegal-state-exception&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In sharp contrast to these, we have the situation where you cannot complete the call for a domain logical reason.  In this case we have encountered a situation that is an exception, i e unusual, but not bizarre or erroneous in any way. For example, if I try to withdraw money from an ATM but balance is not sufficient, it is an unusual situation but not un-normal. In other words this kind of situation is a part of the contract, and throwing an exception is just an “alternative return” that is part of the model and that the client should understand well, take into account and be prepared to handle. For these situations it is suitable&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/del&gt;and advisable to create a specific exception&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/del&gt;or a separate exception hierarchy so that the client can precisely catch and handle the situation, e g &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;InsufficientBalanceException. If the exceptional situation is critical to handle, you might even consider making this a checked &lt;/del&gt;exception &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;thus taking the compiler to assist in forcing your clients to consider this special case. That design choice is however far from clear-cut&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;A different, but still technical, situation is when the program cannot proceed due to some deficiency in the runtime environment, for example if a necessary database does not respond. In this situation you must assume that the infrastructure has done what it can to try to resolve the situation, e g repairing connections and retrying a fair amount of times. Even if the cause is different, the situation for the code is similar: there is nothing to do about it. So, we signal the situation through an exception that we let bubble up to the general exception handling mechanism. This is also the behaviour seen in several frameworks such as Spring or Hibernate.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In sharp contrast to these, we have the situation where you cannot complete the call for a domain logical reason.  In this case we have encountered a situation that is an exception, i e unusual, but not bizarre or erroneous in any way. For example, if I try to withdraw money from an ATM but balance is not sufficient, it is an unusual situation but not un-normal. In other words this kind of situation is a part of the contract, and throwing an exception is just an “alternative return” that is part of the model and that the client should understand well, take into account&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;and be prepared to handle. For these situations it is suitable and advisable to create a specific exception or a separate exception hierarchy so that the client can precisely catch and handle the situation, e g &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;insufficient-balance-&lt;/ins&gt;exception. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Mixing technical exceptions and business exceptions in the same hierarchy blurs the distinction and confuses the caller about what the method contract is, what conditions it is required to ensure before calling and what situations it is supposed to handle. Separating the cases gives clarity and increases the chances that technical exceptions are let to be handled by some application framework, while the business domain model exceptional situations actually are considered and handled by the client code.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Mixing technical exceptions and business exceptions in the same hierarchy blurs the distinction and confuses the caller about what the method contract is, what conditions it is required to ensure before calling and what situations it is supposed to handle. Separating the cases gives clarity and increases the chances that technical exceptions are let to be handled by some application framework, while the business domain model exceptional situations actually are considered and handled by the client code.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Danbj</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=21788&amp;oldid=prev</id>
		<title>Danbj: Changed to conform with standard layout</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=21788&amp;oldid=prev"/>
				<updated>2008-11-26T18:38:45Z</updated>
		
		<summary type="html">&lt;p&gt;Changed to conform with standard layout&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 18:38, 26 November 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Distinguish Business Exceptions from Technical&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong during runtime. Either there is some technical problem or there is some business logical reason that we cannot proceed. Both of these are situations are usually signalled through exceptions. However, the situations are so different that they should be carefully held apart. As a contrast, it is for example a dangerous source for confusion by representing them both using the same exception hierarchy, not to mention using the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;There are basically two reasons that things go wrong during runtime. Either there is some technical problem or there is some business logical reason that we cannot proceed. Both of these are situations are usually signalled through exceptions. However, the situations are so different that they should be carefully held apart. As a contrast, it is for example a dangerous source for confusion by representing them both using the same exception hierarchy, not to mention using the same exception class.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Mixing technical exceptions and business exceptions in the same hierarchy blurs the distinction and confuses the caller about what the method contract is, what conditions it is required to ensure before calling and what situations it is supposed to handle. Separating the cases gives clarity and increases the chances that technical exceptions are let to be handled by some application framework, while the business domain model exceptional situations actually are considered and handled by the client code.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Mixing technical exceptions and business exceptions in the same hierarchy blurs the distinction and confuses the caller about what the method contract is, what conditions it is required to ensure before calling and what situations it is supposed to handle. Separating the cases gives clarity and increases the chances that technical exceptions are let to be handled by some application framework, while the business domain model exceptional situations actually are considered and handled by the client code.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[Dan Bergh Johnsson]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;This work is licensed under a [http://creativecommons.org/licenses/by/3.0/us/ Creative Commons Attribution 3] &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Back to [[97 Things Every Programmer Should Know]] home page&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Danbj</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=21743&amp;oldid=prev</id>
		<title>Danbj: First draft</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Distinguish_Business_Exceptions_from_Technical&amp;diff=21743&amp;oldid=prev"/>
				<updated>2008-11-25T15:36:29Z</updated>
		
		<summary type="html">&lt;p&gt;First draft&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Distinguish Business Exceptions from Technical&lt;br /&gt;
&lt;br /&gt;
There are basically two reasons that things go wrong during runtime. Either there is some technical problem or there is some business logical reason that we cannot proceed. Both of these are situations are usually signalled through exceptions. However, the situations are so different that they should be carefully held apart. As a contrast, it is for example a dangerous source for confusion by representing them both using the same exception hierarchy, not to mention using the same exception class.&lt;br /&gt;
&lt;br /&gt;
When an irresolvable technical problem occurs, there is usually not much the calling client code can do about it. If for example a necessary database does not respond, you must assume that the infrastructure has done what it can to try to resolve the situation, e g repairing connections and retrying a fair amount of times. So, as a client there is not much idea of catching and handling these kinds of exceptions. Instead we probably let them bubble up to the highest architectural level and let some general exception handling mechanism do what it can to ensure the system is in a safe state (ensuring transaction rollback et al), log and alert administration, and report to the user in some neat way. &lt;br /&gt;
&lt;br /&gt;
Obviously exceptions signalling irresolvable technical problems should be unchecked so that they transparently can “bubble through”. Some infrastructure APIs, e g “java.sql”, force their clients to catch and handle exceptions, and in that situation there is basically one reasonable thing to do – wrap the exception in some unchecked exception, add contextual data, and re-throw the wrapped version. If you are in an EJB container, then the EJBException (which extends RuntimeException) was created for precisely this reason, and other frameworks have a similar construct. In general decent choices could be IllegalStateException or RuntimeException itself.&lt;br /&gt;
&lt;br /&gt;
A variant of an irresolvable technical problem is if you realise that the client calling your code has made a mistake. E g you could realise that they have called your method with a totally bizarre argument, or that they have not made the proper setup of a dependent object. Actually, this is as bad as trying to get the 47th element out of an array of length 32. The caller should have checked, and not doing so is a breach against the contract of your method and a programmer error on the client side. The proper response again is throwing some unchecked exceptions, e g IllegalArgumentException or IllegalStateException.&lt;br /&gt;
&lt;br /&gt;
In sharp contrast to these, we have the situation where you cannot complete the call for a domain logical reason.  In this case we have encountered a situation that is an exception, i e unusual, but not bizarre or erroneous in any way. For example, if I try to withdraw money from an ATM but balance is not sufficient, it is an unusual situation but not un-normal. In other words this kind of situation is a part of the contract, and throwing an exception is just an “alternative return” that is part of the model and that the client should understand well, take into account and be prepared to handle. For these situations it is suitable, and advisable to create a specific exception, or a separate exception hierarchy so that the client can precisely catch and handle the situation, e g InsufficientBalanceException. If the exceptional situation is critical to handle, you might even consider making this a checked exception thus taking the compiler to assist in forcing your clients to consider this special case. That design choice is however far from clear-cut.&lt;br /&gt;
&lt;br /&gt;
Mixing technical exceptions and business exceptions in the same hierarchy blurs the distinction and confuses the caller about what the method contract is, what conditions it is required to ensure before calling and what situations it is supposed to handle. Separating the cases gives clarity and increases the chances that technical exceptions are let to be handled by some application framework, while the business domain model exceptional situations actually are considered and handled by the client code.&lt;/div&gt;</summary>
		<author><name>Danbj</name></author>	</entry>

	</feed>