forcing value to bool

Started by
14 comments, last by Paul Dolhai 22 years ago
quote:Original post by DrPizza
Exceptions are not free.

Nobody said they were.
quote:
Exceptions are not universally available; particularl environments may not have them, interopability constraints may not permit them.

But we''re not talking about any of those environments.
quote:
And most importantly, most error conditions are not exceptional.

Which is a reasonable statement. However, it would appear Paul has already decided that a bool is sufficient to capture the needed return value from his function for the "normal" flow of control to continue. Once that decision has been made, I don''t see any need to clutter the code with transporting exceptional error information along with the standard processing, as the AP was suggesting. For example, he had an "out of memory" return code in his example, and I wanted to find out what his specific objection was to using exceptions to transport that sort of information.

[C++ FAQ Lite | ACCU | Boost | Stroustrup on Learning C++]
Advertisement
quote:Original post by SabreMan
But we''re not talking about any of those environments.

We don''t know that.

quote:Which is a reasonable statement. However, it would appear Paul has already decided that a bool is sufficient to capture the needed return value from his function for the "normal" flow of control to continue. Once that decision has been made, I don''t see any need to clutter the code with transporting exceptional error information along with the standard processing, as the AP was suggesting. For example, he had an "out of memory" return code in his example, and I wanted to find out what his specific objection was to using exceptions to transport that sort of information.

This is rather beside the point; my objection is to your "that''s what exceptions are for". I don''t agree that they are; exceptions are for indicating something exceptional has happened. Return values are for indicating non-exceptional success/failure conditions.

The AP''s post did, however, mix the two; under most circumstances, running out of memory is exceptional; under most circumstances, a file not being found is not. So whilst some of those error conditions arguably should have been trapped with exceptions, leaving others as return values still strikes me as the correct thing to do.



As for Paul''s, I think he''d be better off returning 0 for success, non-zero for particular errors (and not the same non-zero value, either; something you can test and react to if you need to) and exceptions for exceptional circumstances. It may be that he has no exceptional and/or non-exceptional failure modes for this function, but we can''t tell.
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
quote:Original post by DrPizza
We don''t know that.

I''m *very* sure we are talking about MSVC++.
quote:
This is rather beside the point;

It''s not beside my point. My point being that I wanted to know why Billy objects to exceptions, particularly in code where he is checking for such conditions as running out of memory.
quote:
my objection is to your "that''s what exceptions are for". I don''t agree that they are; exceptions are for indicating something exceptional has happened. Return values are for indicating non-exceptional success/failure conditions.

Yes, that doesn''t contradict my understanding in any way, and is something I''ve been telling people for several years. However, that does nothing to help me understand Billy''s reasoning. I *know* what my thoughts on exceptions are, and now I know what your thoughts are. However, you''re not the person who posted the code that I was curious about.

[C++ FAQ Lite | ACCU | Boost | Stroustrup on Learning C++]
quote:I''m *very* sure we are talking about MSVC++.

I dunno about you, but I''ve written code in MSVC++ that''s had to be called from other languages and other compilers; if that function were exported from a DLL, for instance, there''s no way I''d advocate throwing an exception, because there''s no way of knowing what the calling code is going to make of it.
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
quote:It''s not beside my point. My point being that I wanted to know why Billy objects to exceptions, particularly in code where he is checking for such conditions as running out of memory.

It''s entirely beside the point. I don''t care why Billy says to do something -- I only care that you said, in response to Billy''s statement "I can return errors", "this is what exceptions are for". No, they''re not. Exceptions are for describing the exceptional. Return values are for describing success/failure.

quote:Yes, that doesn''t contradict my understanding in any way,

I''m sorry?

Billy says "I can return errors".

You say "that''s what exceptions are for".

I say "no it isn''t, they''re for indicating exceptional events; errors are for return values".

That certainly contradicts your stated (even if not intended) position.

quote:and is something I''ve been telling people for several years. However, that does nothing to help me understand Billy''s reasoning. I *know* what my thoughts on exceptions are, and now I know what your thoughts are. However, you''re not the person who posted the code that I was curious about.

This is beside the point. We''re not talking about Billy''s motivations, we''re talking about your claim that exceptions are the mechanism for returning error values. They are not.


char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
quote:Original post by DrPizza
This is beside the point. We''re not talking about Billy''s motivations, we''re talking about your claim that exceptions are the mechanism for returning error values. They are not.

So, apparently, in fixating on an earlier post where admittedly, I didn''t state my point too well, you have conveniently ignored a more recent post of mine.

[C++ FAQ Lite | ACCU | Boost | Stroustrup on Learning C++]

This topic is closed to new replies.

Advertisement