This link has been bookmarked by 136 people . It was first bookmarked on 31 Jul 2006, by someone privately.
-
27 Sep 11
-
19 Jul 11
-
27 Jun 11
-
06 Apr 11
-
13 May 10
-
23 Feb 10
-
21 Feb 10
-
27 Jan 10
-
Either log the exception, or throw it, but never do both
-
Logging and throwing results in multiple log messages for a single problem in the code, and makes life hell for the support engineer who is trying to dig through the logs.
-
public void foo() throws Exception {
-
This is generally wrong and sloppy. Catch the specific exceptions that can be thrown
-
This destroys the stack trace of the original exception, and is always wrong.
-
catch (NoSuchMethodException e) { e.printStackTrace(); return null; } // Man I hate this one
-
Instead of returning
null, throw the exception, and let the caller deal with it. You should only returnnullin a normal (non-exceptional) use case (e.g., "This method returns null if the search string was not found."). -
This one is insidious. Not only does it return
nullinstead of handling or re-throwing the exception, it totally swallows the exception, losing the information forever. -
When you're implementing an abstract base class, and you're just providing hooks for subclasses to optionally override, this is fine. However, if this is not the case, you should throw an
UnsupportedOperationExceptioninstead of returningnull. -
It may work fine today, but what happens when the code that you're calling into, or the code that it relies on, changes its underlying implementation, and ends up wrapping the ultimate cause inside of another exception? Now calling
getCausemay return you a wrapping exception, and what you really want is the result ofgetCause().getCause(). Instead, you should unwrap the causes until you find the ultimate cause of the problem. Apache's commons-lang project providesExceptionUtils.getRootCause()to do this easily.
-
-
05 Jan 10
-
29 Dec 09
-
28 Nov 09
-
05 Nov 09
-
15 Sep 09
-
11 Aug 09
arispetridisTim McCune looks at the antipatterns--bad solutions to common problems--found in exception handling code. If you've wondered whether to catch, log, or let an exception go, this article will show you what not to do.
programming java development article design tips reference code exception patterns antipatterns exceptions
-
04 Aug 09
-
12 Jun 09
-
19 Mar 09
-
14 Jan 09
-
08 Jan 09
-
20 Dec 08
Sean LynchA good reference on what not to do with exception handling
-
18 Dec 08
-
12 Dec 08
-
07 Dec 08
-
11 Sep 08
-
25 Jun 08
-
17 Jun 08
-
29 May 08
-
19 May 08
-
12 May 08
Yeray DariasShould you throw an exception, or return null? Should you use checked or unchecked exceptions? For many novice to mid-level developers, exception handling tends to be an afterthought. Their typical pattern is usually a simple try/catch/printStackTrace().
-
09 May 08
-
06 May 08
-
05 May 08
-
03 May 08
-
31 Mar 08
An Ben this article, we'll discuss some fundamental concepts about the different types of Java exceptions and their intended uses. We'll also cover basic logging concepts, especially as they relate to exception handling. Finally, instead of prescribing what to
article java programming exception handling exceptions reference
-
18 Mar 08
-
16 Mar 08
-
05 Mar 08
-
03 Feb 08
-
05 Dec 07
-
02 Oct 07
-
05 Sep 07
-
23 Aug 07
-
11 Jul 07
-
10 Jul 07
-
07 Jul 07
-
20 Jun 07
Dirk EssersTim McCune looks at the antipatterns--bad solutions to common problems--found in exception handling code. If you've wondered whether to catch, log, or let an exception go, this article will show you what not to do.
-
15 Jun 07
-
14 Jun 07
Jose M AragonIn this article, we'll discuss some fundamental concepts about the different types of Java exceptions and their intended uses
-
13 Jun 07
-
Ivan YatskevichTim McCune looks at the antipatterns--bad solutions to common problems--found in exception handling code. If you've wondered whether to catch, log, or let an exception go, this article will show you what not to do.
-
12 Jun 07
Olifante *"instead of prescribing what to do, we'll focus on what not to do, and take a look at a dozen common exception-handling antipatterns that you are almost certain to find somewhere in your code base."
-
11 Jun 07
-
Emmanuel HugonnetIn this article, we'll discuss some fundamental concepts about the different types of Java exceptions and their intended uses. We'll take a look at common exception-handling antipatterns that you are almost certain to find somewhere in your code
-
10 Jun 07
-
09 Jun 07
-
30 May 07
garthofUn artículo que habla sobre algunos antipatrones asociados al manejo de excepciones.
antipatterns java exceptions programming article development
-
25 May 07
-
10 Apr 07
-
21 Mar 07
-
01 Feb 07
-
18 Jan 07
-
06 Dec 06
-
01 Nov 06
-
25 Oct 06
-
20 Oct 06
Isaac RuizException-Handling Antipatterns
best-practices design-patterns PATTERNS reference guidelines programming exception
-
19 Aug 06
-
31 Jul 06
-
07 Jul 06
-
06 Jul 06
-
13 Jun 06
-
23 May 06
jordimThis article shows how any application that uses JDBC directly (i.e., not through some O/R mapping framework that itself uses JDBC) can easily benefit from Spring.
-
05 May 06
-
04 May 06
-
23 Apr 06
-
14 Apr 06
-
13 Apr 06
-
12 Apr 06
-
11 Apr 06
-
10 Apr 06
-
hideaki-tTim McCune looks at the antipatterns--bad solutions to common problems--found in exception handling code. If you've wondered whether to catch, log, or let an exception go, this article will show you what not to do.
-
08 Apr 06
-
auxonne auxonneIn this article, we'll discuss some fundamental concepts about the different types of Java exceptions and their intended uses.
article java patterns exceptions bestpractices to.cri.n2 to.read to.blog
-
07 Apr 06
-
dirtyaffairsAnti-patrones de gestión de excepciones (ejemplos de como no se deberían gestionar las excepciones en Java)
-
sourcerebelsAnti-patrones de gestión de excepciones (ejemplos de como no se deberían gestionar las excepciones en Java)
-
ifolmedoArtículos sobre antipatrones en el uso de Excepciones.
-
06 Apr 06
-
05 Dec 05
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.