Sweep It Under The Rug Anti Pattern

This is an AntiPattern, typically found in C++ code, but that can also appear in languages like Java, where the programmers catch the basemost exception silently and move on as if nothing happened.

A typical example in C++ is the following:

 try
 {
   ... do something dangerous ...
 }
 catch(...)
 {
   ... do nothing ...
 }

A typical example in Java is the following:

 try
 {
   ... do something dangerous ...
 }
 catch(Exception e)
 {
   ... do nothing ...
 }

This anti-pattern appears to be employed most often naive or lazy programmers who want to avoid an exception accidentally propagating to higher levels and skipping over important logic. Instead of writing correct handling code, or at least logging, they almost treat exceptions like error codes which can simply be ignored. In my experience, this leads to very fragile systems, in which resource leaks and deadlocks are very common on "bad" days. Even worse is that things often "appear" to work but have seemingly random failures.


Seems like this is the same as ExceptionFunnel - refactor?


As a Software Pattern, "sweeping it under the rug" more commonly refers to hiding bad code (http://www.laputan.org/mud/mud.html#SweepingItUnderTheRug), and less to dropping exceptions.


CategoryAntiPattern CategoryDevelopmentAntiPattern


EditText of this page (last edited August 2, 2012) or FindPage with title or text search