Article 6KT5P CodeSOD: Gotta Catch 'Em All

CodeSOD: Gotta Catch 'Em All

by
Remy Porter
from The Daily WTF on (#6KT5P)

It's good to handle any exception that could be raised in some useful way. Frequently, this means that you need to take advantage of the catch block's ability to filter by type so you can do something different in each case. Or you could do what Adam's co-worker did.

try{/* ... some important code ... */} catch (OutOfMemoryException exception) { Global.Insert("App.GetSettings;", exception.Message);} catch (OverflowException exception) { Global.Insert("App.GetSettings;", exception.Message);} catch (InvalidCastException exception) { Global.Insert("App.GetSettings;", exception.Message);} catch (NullReferenceException exception) { Global.Insert("App.GetSettings;", exception.Message);} catch (IndexOutOfRangeException exception) { Global.Insert("App.GetSettings;", exception.Message);} catch (ArgumentException exception) { Global.Insert("App.GetSettings;", exception.Message);} catch (InvalidOperationException exception) { Global.Insert("App.GetSettings;", exception.Message);} catch (XmlException exception) { Global.Insert("App.GetSettings;", exception.Message);} catch (IOException exception) { Global.Insert("App.GetSettings;", exception.Message);} catch (NotSupportedException exception) { Global.Insert("App.GetSettings;", exception.Message);} catch (Exception exception) { Global.Insert("App.GetSettings;", exception.Message);}

Well, I guess that if they ever need to add different code paths, they're halfway there.

buildmaster-icon.png [Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments