M
Marcin Vorbrodt
Exactly. Macros are not ('assert' is a macro) in a namespace.
They cannot be, since they're merely text substitutions.
It's fine.
-MIke
Thanks a lot! Makes sense.
Martin.
Exactly. Macros are not ('assert' is a macro) in a namespace.
They cannot be, since they're merely text substitutions.
It's fine.
-MIke
[email protected] says... said:Heh heh. So am I, but I hope no one thinks I'm an expert.
[snip]Kevin Goodsell said:Gianni said:OK - time for some friendly debate.Kevin said:- You definitely do NOT want to throw an exception in case of a
contract violation. It is very, very rare, if ever, that this is
correct. The program is incorrect, and you abort.
The fact that every function can potentially throw an exception
makes writing exception safe code pratically impossible.
A lot of people seem to want exceptions anyway. To keep them
happy, I would suggest some sort of callback, which the user can
replace. By default, the code should abort. If the user replaces
it with something which will throw, his code probably will not work
when the exception occurs. But since that's what he wanted...
This sounds like someone who doesn't understand exceptions to me.
I'll state that I use exceptions very rarely and hardly ever in
production code.
I actually agree the the quote 100% because I have done exactly that
and found that it is a very acceptable paradigm for developing solid
and easily maintainable code.
I don't think that library code should ever unilaterally abort the
program. Besides that, doing so causes objects to go undestructed,
leading to resource leaks (sure, most modern desktop systems clean up
when the process terminates, but you can't count on that in portable
code).
I don't understand why you would prefer aborting to throwing an
exception anyway. What's the worst case for throwing an exception?
It's not caught, and the program aborts. So by aborting instead of
throwing, you're ensuring that you always get the worst case.
Kevin Goodsell said:A few ideas come to mind, but none is anywhere near perfect. You could
abort or throw depending on a build setting, for example. But if you
test with abort and ship with throw then you don't even know if the
catching code is in place or doing anything sensible. You'd have to test
with throw, and it could be covered up.
For the record, I wasn't really considering the context of the quoted
message, just exception handling in general.
But looking at just the contract violation case, obviously it's a bug
that should be fixed. But at least some bugs always make it into the
final product. Terminating the program when a problem is found is not a
very useful behavior from the perspective of the user of the
application. In fact, I don't think most users would be very happy with
that.
Yes, I agree that this is bad. But it only happens if you explicitly
ignore the exception.
This is not true from the user's perspective, though.
Yes, I definitely agree that this is a problem. But one way to look at
it is that it's not really *your* problem. If you threw the exception,
you've done your part. If the caller ignores it, then they screwed up.
But this doesn't make any difference in many cases. If the program
breaks for the customer, you'll still be in trouble.
You could try to make an un-ignorable exception, maybe. Suppose your
exception object includes a 'handled' flag. On construction, this flag
is false. The catcher must set it to true. On destruction, if the flag
does not indicate that the exception was handled, the destructor aborts
the program. The problem is that it can still be ignored, it just takes
a little more effort (catch, set the flag, do nothing else).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.