a life of coding

Friday, March 25, 2005

Exceptional C++

In other fluffy, inefficient lanuages like Java, exceptions are all derived from one base. This has the unfortunate side effect of catching all exceptions whenever you catch (Exception e). Fortunately, the C++ code I am working with does no such clustering - if you would like to catch FileFormatException, then you best catch it or catch (...). Otherwise, it is left to some other code to deal with this stray. Useful? Maybe. Infuriating? Certainly. My impression so far is that every exception should derive from a common base (probably std::exception), so that you can always tell the user something. If you must instead take the tragic path of catching (...), then your error message will probably look something like this:

"An exception has ocurred. Sorry."

Because you don't have any idea what happened - only that something happened. Let me set you on the right path: knowing that something happened isn't useful to anyone - including yourself. Check your parents, kids - std::exception is your friend.

4 Comments:

  • Arguments of unfluffiness aside, have you ever coded c++ when you didn't have to?

    By Anonymous Steve, At 3/28/05 3:33 PM  

  • Yes, I posted 3 times on purpose. I swear.

    By Anonymous Steve, At 3/28/05 3:35 PM  

  • I also swear that two of those posts just disappeared into the bit bucket - I had nothing to do with it. No, I haven't used C++ when there was a choice. I think the mertits of C++ (faster code, generics, ability to hire programmers from Bolivia) are pretty well squashed by the line-efficiency of other languages (python, objc). Basically, I don't like C++ for the same reasons that I don't like Java - and I can't run C++ cross platform.

    By Blogger ynniv, At 3/28/05 3:45 PM  

  • Neither have I, except I actually had a positive experience with it on Growbot.

    Veering further off topic, one extremely elementary thing I couldn't figure out in C++ was how to make a object contain a pointer of own type. The Visual C++ 6 compiler always disagreed with me. I actually ended up just using and casting void pointers for this purpose which worked fine but seemed stoopid.

    Have you run into this?

    By Anonymous Steve, At 3/28/05 4:52 PM  

Post a Comment



<$I18N$LinksToThisPost>:

Create a Link

<< Home