Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 11 Mar 2012 17:26:20 -0500 Date: Sun, 11 Mar 2012 15:26:19 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:10.0.1) Gecko/20120208 Thunderbird/10.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Exception Handling References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 31 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.206.198 X-Trace: sv3-nyrEA1yiKN5snCKctsVT4iEZLEr3XjVDDyFQNdPr/6L5NBP38SwhRbtLr06xApbgBQuFE5i4zlzj1eL!uHkpIBwWyoMG2VhvryNjSKTbIUrkhNKNv+IdIUdLoHVpWK9LxIICUNAHzL8lzBGpb7n8eqMeB2wf!v4y7Uc69hFjCZ0X/WB6C58/AsNTcWxGnCtyRehJhWvaLSVU= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2743 Xref: csiph.com comp.lang.java.programmer:12883 On 3/11/2012 2:54 PM, Novice wrote: > Lew wrote in news:jjipli$np7$1@news.albasani.net: ... >> It is common and frequently useful to create an application-specific >> checked exception. Again, and I've said this many times, think about >> what will be useful when troubleshooting a problem. Many times, a >> custom exception is useful. It says that the underlying exception has >> been caught, logged and wrapped. >> > But how is a custom FooException better than a good ol' > IllegalArgumentException? I'm not quite getting that yet. Generally, you should use different Exception subclasses for cases that may need different handling, so that callers can set up appropriate catch blocks. Regardless of the conditions under which you choose to generate IllegalArgumentException, many methods you will be calling use it to indicate an illegal argument condition that has not yet been logged or otherwise reported. If you also use it to indicate exceptions that have already been logged, you risk either repeated logging of the same issue, or failure to log. On the other hand, if you create an Exception subclass that you only throw after logging the underlying problem, there is no ambiguity. Callers have to deal with the consequences of the failure, but should only generate log messages if they have something to add. The underlying problem has already been logged. Patricia