Article 2SSR0 CodeSOD: Classic WTF: It's Like Calling Assert

CodeSOD: Classic WTF: It's Like Calling Assert

by
Alex Papadimoulis
from The Daily WTF on (#2SSR0)
We continue our summer vacation with this gem- a unique way to interact with structured exception handling, to be sure. Original. --Remy

When we go from language to language and platform to platform, a whole lot of "little things" change about how we write code: typing, syntax, error handling, etc. Good developers try to adapt to a new language by reading the documentation, asking experienced colleagues, and trying to follow best practices. "Certain Developers," however, try to make the language adapt to their way of doing things.

Adrien Kunysz discovered this following code written by a "Certain Developer" who wasn't a fan of the try...catch"finally approach called for in .NET Java development and exception handling.

 /** * Like calling assert(false) in C. */ protected final void BUG (String msg) { Exception e = null; try { throw new Exception (); } catch (Exception c) { e = c; } logger.fatal (msg, e); System.exit (1); }

And I'm sure that, by commenting "Like calling assert(false) in C," the author doesn't mean assert.h, but means my_assert.h. After all, who is C - or any other language - to tell him how errors should be handled?

UPDATE: Fixed Typos and language. I swear, at 7:00AM this looked fine to me...

puppetlabs50.png[Advertisement] Manage IT infrastructure as code across all environments with Puppet. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your free trial today! TheDailyWtf?d=yIl2AUoC8zAKL-P9TIsQik
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