[Novalug] C compilers

jecottrell3@comcast.net jecottrell3@comcast.net
Wed Mar 31 18:27:57 EDT 2010


While it is true that Exception Handling (like anything else) can be misused, what is your alternative? Using Error Return Codes? NOPE, that is Totally Insane, which is a shame considering that it seems to be SOP throughout most of computing history.

I'd say go read the chapter in Perl Best Practices on exceptions vs error codes, except that this book seems to have disappeared, which is a shame, because it's one of the few attempts to reign in Perl to a manageable subset of reasonable features. But your Public Library most likely has a copy.

The problem with error codes is that they are too often not checked, which means that they will often show up later, far removed from the actual cause of the problem.

Checking them is not much better, leading to a bloated style where every possible function call for the form

status = function(args...) expands into

status = function(args...)

if (status == error) {
    complain();
    fix_or_die();
}

Another problem is that this chain of error codes must be propagated back and check for at each level, meaning that few if any of your functions can ignore errors.

And it's not always easy to know which functions will have error codes and which ones won't. Of course that is true with Exceptions as well, but in the case of compiled languages like Java, the compiler will tell you what you either need to handle or make excuses (throws ...) for.

Given that there is always One More Bug in every program, how do you want them to fail? I would prefer Instant Death to Wild Goose Chases later on, along with possible database or similar corruption.

Also, HLLs that have Exception Mechanisms tens to have Good Ones, so the proper catch/throw or try/catch and unwind-protect or finally/ensure clauses will get executed in any case.

I'll note that the "atexit" function is a crude attempt at exception handling at the program level, as are the BEGIN and END block in AWK, Perl, and RUBY.

No, my friend, Exceptions Are Your Friend. Embrace Them.

JIM


----- Original Message -----
From: "John Franklin" <franklin@elfie.org>
To: "Bryan J Smith" <b.j.smith@ieee.org>
Cc: waltechmail@yahoo.com, novalug@calypso.tux.org
Sent: Wednesday, March 31, 2010 1:54:50 AM GMT -05:00 US/Canada Eastern
Subject: Re: [Novalug] C compilers


On Mar 31, 2010, at 1:28 AM, Bryan J Smith wrote:
> Just build a pre-processor then.  Without all the classes and other
> components, it probably wouldn't be difficult to add the exception and
> other event handling.
> 
> And although it's not C, don't forget about Objective-C.  Many people
> still prefer Objective-C for such features, instead of C++.


Indeed.  The earliest C++ "compilers" were just pre-processors for existing 'C' compilers.

I've been developing in Objective-C for about a year now and I love the language, far more than I liked C++, even when I started with C++.

That said, I've never liked exception handling because it is too easy to misuse it and leave yourself with hidden, non-obvious paths in your code that leaks memory, is difficult to debug, and makes a mess of any code analysis.

jf
_______________________________________________
Novalug mailing list
Novalug@calypso.tux.org
http://calypso.tux.org/mailman/listinfo/novalug



More information about the Novalug mailing list