<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: What&#8217;s the Best Way to Handle Exceptions?</title>
	<atom:link href="http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/</link>
	<description>Commercial-Friendly Open Source Software Development</description>
	<lastBuildDate>Fri, 05 Mar 2010 13:52:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Rob Whelan</title>
		<link>http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/comment-page-1/#comment-240</link>
		<dc:creator>Rob Whelan</dc:creator>
		<pubDate>Tue, 07 Oct 2008 17:38:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.kallasoft.com/?p=296#comment-240</guid>
		<description>@Tracy -- Ah, now I see what you&#039;re talking about.  Agreed, an error should never get to the level where the entire process aborts.  I pretty much assume any program or web-app has a net for generic errors (usu. Throwable) at some high level, to handle them in a generic way.

(Looking back at my comment, I didn&#039;t mean &quot;halt execution&quot;, I mean halt execution of that transaction so the application could continue cleanly).

So I think the pattern you&#039;re actually using is just hiding the internal implementation of your message handler -- which makes sense because the calling code has no interest in the specific implementation of each handler, so that shouldn&#039;t be a part of that external interface.

Curious: is your &quot;XYZHandlerException&quot; a checked exception?</description>
		<content:encoded><![CDATA[<p>@Tracy &#8212; Ah, now I see what you&#8217;re talking about.  Agreed, an error should never get to the level where the entire process aborts.  I pretty much assume any program or web-app has a net for generic errors (usu. Throwable) at some high level, to handle them in a generic way.</p>
<p>(Looking back at my comment, I didn&#8217;t mean &#8220;halt execution&#8221;, I mean halt execution of that transaction so the application could continue cleanly).</p>
<p>So I think the pattern you&#8217;re actually using is just hiding the internal implementation of your message handler &#8212; which makes sense because the calling code has no interest in the specific implementation of each handler, so that shouldn&#8217;t be a part of that external interface.</p>
<p>Curious: is your &#8220;XYZHandlerException&#8221; a checked exception?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tracy</title>
		<link>http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/comment-page-1/#comment-239</link>
		<dc:creator>Tracy</dc:creator>
		<pubDate>Tue, 07 Oct 2008 15:56:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.kallasoft.com/?p=296#comment-239</guid>
		<description>@Rob: Most of the code I write is &quot;message handlers&quot;, which get called several times a second.  If my handler throws an exception, the whole server (process, not the machine) aborts and has to be restarted, so it&#039;s very important that exceptions *never* &quot;get to the top&quot;.  In most of my components, the main routine consists of a try/catch block that catches Throwable.  That way, everything (even Errors) gets caught.  Then I wrap that in a specific XYZHandlerException and throw that to my top-level message handler.  Our exception handler base class has specific fields for disposition (log routing, notification list, severity, etc), so the message handler just takes any exceptions and passes them to an exception reporter which DTRT.</description>
		<content:encoded><![CDATA[<p>@Rob: Most of the code I write is &#8220;message handlers&#8221;, which get called several times a second.  If my handler throws an exception, the whole server (process, not the machine) aborts and has to be restarted, so it&#8217;s very important that exceptions *never* &#8220;get to the top&#8221;.  In most of my components, the main routine consists of a try/catch block that catches Throwable.  That way, everything (even Errors) gets caught.  Then I wrap that in a specific XYZHandlerException and throw that to my top-level message handler.  Our exception handler base class has specific fields for disposition (log routing, notification list, severity, etc), so the message handler just takes any exceptions and passes them to an exception reporter which DTRT.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Whelan</title>
		<link>http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/comment-page-1/#comment-237</link>
		<dc:creator>Rob Whelan</dc:creator>
		<pubDate>Mon, 06 Oct 2008 16:58:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.kallasoft.com/?p=296#comment-237</guid>
		<description>I posted more detail in a blog entry (see trackback), but a few comments:

@Michael: absolutely -- the checked reflection errors are annoying because that&#039;s pretty much guaranteed to be programmer error, and the error just needs to bubble up to the top level and be reported.  I have a simple reflection utility wrapper that basically just wraps those errors in an unchecked exception with good debugging detail if something does break.

@Litty: agreed, don&#039;t show your user a big stack trace with all of your internal debugging info.  They generally won&#039;t get anything from that info, and it could be exploited.  I generally have two error displays (talking webapps for the moment), one for development/testing (which shows all error info plus dumps the current request, session, cookies, etc. to the screen), and another for production (which just says there was an internal error that has been reported automatically, they can try again or contact technical support if it keeps happening).

@Tracy: I agree you shouldn&#039;t have to think about exceptions in most of the code -- generally they&#039;d indicate a coding error, and should just halt execution, because something has failed.  Put in &quot;try-finally&quot; blocks to make sure resources get cleaned up where needed and otherwise let exceptions bubble up.  But what do you mean you wrap them at higher levels?  Won&#039;t they just reach the top and get trapped/logged/handled?

I vary in how I handle IO and database connection issues... IO in a client application probably should be checked, because actions that use IO will quite probably fail occasionally (the network is down, the file is locked by another process, etc.) and need to be handled better than just a generic error.  On the server... I go back and forth.  At the moment my webapps mostly have checked exceptions for database access, because they *do* get caught and wrapped (with all details of the query included) and to remind developers that resources must be cleaned up as part of error handling.  That wrapper that&#039;s rethrown could logically be unchecked, though.

@Riyad: No special libraries; I do have a set of standard error handling code &amp; approaches that I reuse from project to project, but it&#039;s hard to encapsulate that kind of thing into a separate utility.  I used to have custom wrapper exceptions, until the JDK added that feature. :)</description>
		<content:encoded><![CDATA[<p>I posted more detail in a blog entry (see trackback), but a few comments:</p>
<p>@Michael: absolutely &#8212; the checked reflection errors are annoying because that&#8217;s pretty much guaranteed to be programmer error, and the error just needs to bubble up to the top level and be reported.  I have a simple reflection utility wrapper that basically just wraps those errors in an unchecked exception with good debugging detail if something does break.</p>
<p>@Litty: agreed, don&#8217;t show your user a big stack trace with all of your internal debugging info.  They generally won&#8217;t get anything from that info, and it could be exploited.  I generally have two error displays (talking webapps for the moment), one for development/testing (which shows all error info plus dumps the current request, session, cookies, etc. to the screen), and another for production (which just says there was an internal error that has been reported automatically, they can try again or contact technical support if it keeps happening).</p>
<p>@Tracy: I agree you shouldn&#8217;t have to think about exceptions in most of the code &#8212; generally they&#8217;d indicate a coding error, and should just halt execution, because something has failed.  Put in &#8220;try-finally&#8221; blocks to make sure resources get cleaned up where needed and otherwise let exceptions bubble up.  But what do you mean you wrap them at higher levels?  Won&#8217;t they just reach the top and get trapped/logged/handled?</p>
<p>I vary in how I handle IO and database connection issues&#8230; IO in a client application probably should be checked, because actions that use IO will quite probably fail occasionally (the network is down, the file is locked by another process, etc.) and need to be handled better than just a generic error.  On the server&#8230; I go back and forth.  At the moment my webapps mostly have checked exceptions for database access, because they *do* get caught and wrapped (with all details of the query included) and to remind developers that resources must be cleaned up as part of error handling.  That wrapper that&#8217;s rethrown could logically be unchecked, though.</p>
<p>@Riyad: No special libraries; I do have a set of standard error handling code &amp; approaches that I reuse from project to project, but it&#8217;s hard to encapsulate that kind of thing into a separate utility.  I used to have custom wrapper exceptions, until the JDK added that feature. <img src='http://www.kallasoft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Riyad Kalla</title>
		<link>http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/comment-page-1/#comment-236</link>
		<dc:creator>Riyad Kalla</dc:creator>
		<pubDate>Mon, 06 Oct 2008 12:40:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.kallasoft.com/?p=296#comment-236</guid>
		<description>I want to thank everyone for their replies so far, they have been hugely helpful.

@Michael/Dimitris,
That is *exactly* what I was looking for and curious about. My gut told me that working with checked exceptions (atleast when I did it) drove me nuts, try-catching even the smallest operation was really slowing me down, because then you run into the situation where you need to decide how granular you want your try-catch and detailed handling to be and that can turn into an art-form or a nightmare just in and of itself.

@Litty/Tracy/Parth,
An even higher level take that I wasn&#039;t considering but can be just as important: what to do with the exceptions. I appreciate you weighing in.

Now I suppose a followup question would be:

Does anyone have any favorite exception handling/logging libraries out there that fit their work flow like a glove?</description>
		<content:encoded><![CDATA[<p>I want to thank everyone for their replies so far, they have been hugely helpful.</p>
<p>@Michael/Dimitris,<br />
That is *exactly* what I was looking for and curious about. My gut told me that working with checked exceptions (atleast when I did it) drove me nuts, try-catching even the smallest operation was really slowing me down, because then you run into the situation where you need to decide how granular you want your try-catch and detailed handling to be and that can turn into an art-form or a nightmare just in and of itself.</p>
<p>@Litty/Tracy/Parth,<br />
An even higher level take that I wasn&#8217;t considering but can be just as important: what to do with the exceptions. I appreciate you weighing in.</p>
<p>Now I suppose a followup question would be:</p>
<p>Does anyone have any favorite exception handling/logging libraries out there that fit their work flow like a glove?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Parth Barot</title>
		<link>http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/comment-page-1/#comment-235</link>
		<dc:creator>Parth Barot</dc:creator>
		<pubDate>Mon, 06 Oct 2008 11:55:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.kallasoft.com/?p=296#comment-235</guid>
		<description>Very nice and informative post mates.I really liked it.

I like to throw exceptions at the lower level and will track it in my calling code (using some DB status etc...which can be used to notify users etc.. ).Main thing is,we should log it so properly(in log and DB both if possible) that the developer/System Admin can track down the error easily while digging into the huge log file :).Because i had been through this situation a lot more times, i know how important to track exceptions if you want to keep you app. running up.

I mostly use checked exceptions,and mostly use diff. statuses for my business logic processes which can give me a proper indication.

regards,
www.techlads.com</description>
		<content:encoded><![CDATA[<p>Very nice and informative post mates.I really liked it.</p>
<p>I like to throw exceptions at the lower level and will track it in my calling code (using some DB status etc&#8230;which can be used to notify users etc.. ).Main thing is,we should log it so properly(in log and DB both if possible) that the developer/System Admin can track down the error easily while digging into the huge log file <img src='http://www.kallasoft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .Because i had been through this situation a lot more times, i know how important to track exceptions if you want to keep you app. running up.</p>
<p>I mostly use checked exceptions,and mostly use diff. statuses for my business logic processes which can give me a proper indication.</p>
<p>regards,<br />
<a href="http://www.techlads.com" rel="nofollow">http://www.techlads.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tracy</title>
		<link>http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/comment-page-1/#comment-231</link>
		<dc:creator>Tracy</dc:creator>
		<pubDate>Sun, 05 Oct 2008 19:09:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.kallasoft.com/?p=296#comment-231</guid>
		<description>I like to throw RuntimeExceptions in lower-level code, but catch and wrap them at higher levels.  This way, long-lived processes (like service daemons) can continue processing, but I don&#039;t have to explicitly plan for (or think about) exceptions in most of the code.  Business logic exceptions are always thrown as checked, since part of the design should be how to handle and report business logic violations.  But resource exceptions (I/O errors, DB connection pool issues, etc) are always unchecked, since the whole unit of work is unable to be processed and nobody really cares how many processing layers deep it was (&quot;I/O error in foo() -&gt; Resource exception in bar(): I/O error in foo() -&gt; baz(): cannot flotz: resource exception in bar(): I/O error in foo() -&gt; ... &quot;).</description>
		<content:encoded><![CDATA[<p>I like to throw RuntimeExceptions in lower-level code, but catch and wrap them at higher levels.  This way, long-lived processes (like service daemons) can continue processing, but I don&#8217;t have to explicitly plan for (or think about) exceptions in most of the code.  Business logic exceptions are always thrown as checked, since part of the design should be how to handle and report business logic violations.  But resource exceptions (I/O errors, DB connection pool issues, etc) are always unchecked, since the whole unit of work is unable to be processed and nobody really cares how many processing layers deep it was (&#8220;I/O error in foo() -&gt; Resource exception in bar(): I/O error in foo() -&gt; baz(): cannot flotz: resource exception in bar(): I/O error in foo() -&gt; &#8230; &#8220;).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: An Approach to Exception Handling &#124; Just as I had suspected</title>
		<link>http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/comment-page-1/#comment-229</link>
		<dc:creator>An Approach to Exception Handling &#124; Just as I had suspected</dc:creator>
		<pubDate>Sun, 05 Oct 2008 17:39:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.kallasoft.com/?p=296#comment-229</guid>
		<description>[...] response to this post, asking about guidelines different developers have come up with....  I actually started a response [...]</description>
		<content:encoded><![CDATA[<p>[...] response to this post, asking about guidelines different developers have come up with&#8230;.  I actually started a response [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Litty Joseph</title>
		<link>http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/comment-page-1/#comment-227</link>
		<dc:creator>Litty Joseph</dc:creator>
		<pubDate>Sun, 05 Oct 2008 16:34:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.kallasoft.com/?p=296#comment-227</guid>
		<description>Adding very informative messages at each level of exception stack is a good practice. But never dump these accumulated information on the screen of an end user - he probably could be non-friendly and exploit the knowledge of application structure. So redirect the logging to persistent stoarge (text file/database) where the &#039;support engineer&#039; could have a look when he has some time. I had bad experience of such logging IO consuming lot of time and affecting end user response time. A configurable &#039;log level&#039; is a nice feature to incorporate...</description>
		<content:encoded><![CDATA[<p>Adding very informative messages at each level of exception stack is a good practice. But never dump these accumulated information on the screen of an end user &#8211; he probably could be non-friendly and exploit the knowledge of application structure. So redirect the logging to persistent stoarge (text file/database) where the &#8217;support engineer&#8217; could have a look when he has some time. I had bad experience of such logging IO consuming lot of time and affecting end user response time. A configurable &#8216;log level&#8217; is a nice feature to incorporate&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dimitris Menounos</title>
		<link>http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/comment-page-1/#comment-226</link>
		<dc:creator>Dimitris Menounos</dc:creator>
		<pubDate>Sun, 05 Oct 2008 13:18:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.kallasoft.com/?p=296#comment-226</guid>
		<description>I always use well documented unchecked exceptions. Additionally I never try to shallow a thrown exception, instead I just wrap it and re-throw it.

The theory is that exceptions, under normal circumstances, should not happen. If they do happen though, it should be justifiable to halt the execution flow. A good API should offer all its functionality without requiring a single try / catch around it.</description>
		<content:encoded><![CDATA[<p>I always use well documented unchecked exceptions. Additionally I never try to shallow a thrown exception, instead I just wrap it and re-throw it.</p>
<p>The theory is that exceptions, under normal circumstances, should not happen. If they do happen though, it should be justifiable to halt the execution flow. A good API should offer all its functionality without requiring a single try / catch around it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Wiles</title>
		<link>http://www.kallasoft.com/whats-the-best-way-to-handle-exceptions/comment-page-1/#comment-225</link>
		<dc:creator>Michael Wiles</dc:creator>
		<pubDate>Sun, 05 Oct 2008 12:35:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.kallasoft.com/?p=296#comment-225</guid>
		<description>I used to be a big fan of checked exceptions for everything, it&#039;s what the Java API defaults to.

I have since however, since changed to favour unchecked exceptions - but not in every case.

Being forced to catch a myriad of exceptions when you execute a reflective method call where you can&#039;t really do anything to recover is just irritating.</description>
		<content:encoded><![CDATA[<p>I used to be a big fan of checked exceptions for everything, it&#8217;s what the Java API defaults to.</p>
<p>I have since however, since changed to favour unchecked exceptions &#8211; but not in every case.</p>
<p>Being forced to catch a myriad of exceptions when you execute a reflective method call where you can&#8217;t really do anything to recover is just irritating.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
