[Rock-dev] On ignoring exceptions ...

Alexander Duda Alexander.Duda at dfki.de
Tue Sep 17 11:54:15 CEST 2013


To support Sylvain's point here are some code comments which can be 
regarded as bad practice ;-).

Alex

try {}
} catch (PartInitException pie) {
// Mmm… pie
}

try {}
catch (SQLException ex) {
// Basically, without saying too much, you’re screwed. Royally and totally.
}
catch(Exception ex)
{
//If you thought you were screwed before, boy have I news for you!!!
}

try {}
catch (Exception ex)
{
// oh crap, we should do something.
}

On 09/17/2013 11:43 AM, Sylvain Joyeux wrote:
> This is a general programming issue
>
> Catching an exception to ignore it is NOT something that should be done
> lightly. It is a very important act which is hidden behind the fact that
> it takes only (around) two lines of code to do. Why is it so important:
> because ignoring errors, when not done at the right place, can lead to
> 'silent' problems that hit a lot later. Week-long debugging sessions,
> here we are !
>
> This is actually why I strongly prefer exceptions over all other forms
> of error representation and handling: because they cannot be ignored _by
> default_. One has to catch them explicitly.
>
> A fact of the programmer's life is that it sometimes makes sense. Fair
> enough. Now, because it is such an important act (am I stressing that
> enough ?), please HEAVILY describe the rationale of this act in the
> commit that pushes it to the mainline code. Don't be shy. If you don't
> have enough arguments, it is probably that you should not ignore the
> error in the first place.
>
> Thank you in advance for reducing the length of everyone's debugging
> sessions


-- 
Dipl.-Ing. Alexander Duda
Unterwasserrobotik

DFKI Bremen
Robotics Innovation Center
Robert-Hooke-Straße 5
28359 Bremen, Germany

Phone: +49 (0)421 178-456620
Fax:   +49 (0)421 178-454150
E-Mail: alexander.duda at dfki.de

Weitere Informationen: http://www.dfki.de/robotik
-----------------------------------------------------------------------
Deutsches Forschungszentrum fuer Kuenstliche Intelligenz GmbH
Firmensitz: Trippstadter Straße 122, D-67663 Kaiserslautern
Geschaeftsfuehrung: Prof. Dr. Dr. h.c. mult. Wolfgang Wahlster
(Vorsitzender) Dr. Walter Olthoff
Vorsitzender des Aufsichtsrats: Prof. Dr. h.c. Hans A. Aukes
Amtsgericht Kaiserslautern, HRB 2313
Sitz der Gesellschaft: Kaiserslautern (HRB 2313)
USt-Id.Nr.:    DE 148646973
Steuernummer:  19/673/0060/3



More information about the Rock-dev mailing list