Go Back   Rhinocerus > Newsgroup > Newsgroup comp.language.c++

Reply
 
Thread Tools Display Modes
  #106 (permalink)  
Old 12-05-2009, 06:50 AM
dragan
Guest
 
Posts: n/a
Default Re: Why do some code bases don't use exceptions?

peter koch wrote:
> On 1 Dec., 07:05, "dragan" <spambus...@prodigy.net> wrote:


>> Of
>> course, and ironically, the C++ mechanism is derived directly from
>> C's setjmp/longjmp. Whereas programmers once used to evaluate and
>> choose between alternative mechanisms, C++ not only recommends ONE,
>> but "dumbs-down" programmers (read: makes for dangerous programmers,
>> not makes for cheap project labor. Think about it).

>
> No. longjmp/setjmp is not related to exceptions.


Yes, it is. It was an "advanced" EH technique in C and exceptions model that
basic behavior. That's why C++ exceptions are "derived" from that technique.



Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #107 (permalink)  
Old 12-06-2009, 07:37 PM
Richard
Guest
 
Posts: n/a
Default Re: Why do some code bases don't use exceptions?

[Please do not mail me a copy of your followup]

"dragan" <spambuster@prodigy.net> spake the secret code
<_koSm.35491$kY2.22472@newsfe01.iad> thusly:

>> No. longjmp/setjmp is not related to exceptions.

>
>Yes, it is. It was an "advanced" EH technique in C and exceptions model that
>basic behavior. That's why C++ exceptions are "derived" from that technique.


I disagree. It is the weaker of the two (setjmp/longjmp vs. C++
exceptions), not the more advanced. C++ exceptions are in no way
derived from setjmp. setjmp/longjmp is essentially a non-local goto.
It is not an exception, nor does it unwind the stack, it simply
overwrites the stack pointer.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/>

Legalize Adulthood! <http://legalizeadulthood.wordpress.com>
Reply With Quote
  #108 (permalink)  
Old 12-08-2009, 08:15 PM
dragan
Guest
 
Posts: n/a
Default Re: Why do some code bases don't use exceptions?


"Richard" <legalize+jeeves@mail.xmission.com> wrote in message
news:hfh4n0$30u$1@news.xmission.com...
> [Please do not mail me a copy of your followup]
>
> "dragan" <spambuster@prodigy.net> spake the secret code
> <_koSm.35491$kY2.22472@newsfe01.iad> thusly:
>
>>> No. longjmp/setjmp is not related to exceptions.

>>
>>Yes, it is. It was an "advanced" EH technique in C and exceptions model
>>that
>>basic behavior. That's why C++ exceptions are "derived" from that
>>technique.

>
> I disagree. It is the weaker of the two


I made no assertion of the relative "strength" of setjmp/longjmp and C++
exceptions. You did not comprehend the sentence.

> (setjmp/longjmp vs. C++
> exceptions), not the more advanced. C++ exceptions are in no way
> derived from setjmp.


I disagree. The similarity is too uncanny to not be related. As C++ was
designed to formalize and build upon existing C practices, it makes sense.

> setjmp/longjmp is essentially a non-local goto.
> It is not an exception, nor does it unwind the stack, it simply
> overwrites the stack pointer.


No one was suggesting anything of the sort. I'll excuse your
miscomprehension of what I wrote only if English is not your primary
language. (Because I'm tired of all the childish antics in programming
forums).



Reply With Quote
  #109 (permalink)  
Old 12-08-2009, 08:32 PM
peter koch
Guest
 
Posts: n/a
Default Re: Why do some code bases don't use exceptions?

On 8 Dec., 22:15, "dragan" <spambus...@prodigy.net> wrote:
> "Richard" <legalize+jee...@mail.xmission.com> wrote in message


[snip]
>
> > (setjmp/longjmp vs. C++
> > exceptions), not the more advanced. *C++ exceptions are in no way
> > derived from setjmp.

>
> I disagree. The similarity is too uncanny to not be related. As C++ was
> designed to formalize and build upon existing C practices, it makes sense..
>
> > setjmp/longjmp is essentially a non-local goto.
> > It is not an exception, nor does it unwind the stack, it simply
> > overwrites the stack pointer.

>
> No one was suggesting anything of the sort. I'll excuse your
> miscomprehension of what I wrote only if English is not your primary
> language. (Because I'm tired of all the childish antics in programming
> forums).


I believe you told us that you had read "The Design and Evolution of C+
+" by Stroustrup. If that was the case, you'd be aware of the origin
of the C++ exception mechanism. The origin is Ada, and the belief that
a try-block executes anything similar to a setjmp or that a catch
executes anything similar to a longjmp is misleading and wrong.
Not very many would use setjmp/longjmp anywhere outside a tightly
controlled environment for error-management. I've tried doing so in a
very small project and it simply does not work: you risk ressource
leaks anywhere, meaning that you have to do a quite consuming program
analysis every time you allocate any ressource. Not only in the
function you change, but also to check if your function might call
something that might longjmp on you.

/Peter

/Peter
Reply With Quote
  #110 (permalink)  
Old 12-09-2009, 05:44 AM
dragan
Guest
 
Posts: n/a
Default Re: Why do some code bases don't use exceptions?

peter koch wrote:
> On 8 Dec., 22:15, "dragan" <spambus...@prodigy.net> wrote:
>> "Richard" <legalize+jee...@mail.xmission.com> wrote in message

>
> [snip]
>>
>>> (setjmp/longjmp vs. C++
>>> exceptions), not the more advanced. C++ exceptions are in no way
>>> derived from setjmp.

>>
>> I disagree. The similarity is too uncanny to not be related. As C++
>> was designed to formalize and build upon existing C practices, it
>> makes sense.
>>
>>> setjmp/longjmp is essentially a non-local goto.
>>> It is not an exception, nor does it unwind the stack, it simply
>>> overwrites the stack pointer.

>>
>> No one was suggesting anything of the sort. I'll excuse your
>> miscomprehension of what I wrote only if English is not your primary
>> language. (Because I'm tired of all the childish antics in
>> programming forums).

>
> I believe you told us that you had read "The Design and Evolution of
> C+ +" by Stroustrup. If that was the case, you'd be aware of the
> origin of the C++ exception mechanism. The origin is Ada, and the
> belief that a try-block executes anything similar to a setjmp or that
> a catch executes anything similar to a longjmp is misleading and
> wrong.


The pattern is the same. No one suggested that the _mechanisms_ were the
same or even alike. "Jumping across levels" is jumping across levels.



Reply With Quote
  #111 (permalink)  
Old 12-09-2009, 07:18 AM
Joshua Maurice
Guest
 
Posts: n/a
Default Re: Why do some code bases don't use exceptions?

On Dec 9, 1:44*am, "dragan" <spambus...@prodigy.net> wrote:
> peter koch wrote:
> > On 8 Dec., 22:15, "dragan" <spambus...@prodigy.net> wrote:
> >> "Richard" <legalize+jee...@mail.xmission.com> wrote in message

>
> > [snip]

>
> >>> (setjmp/longjmp vs. C++
> >>> exceptions), not the more advanced. C++ exceptions are in no way
> >>> derived from setjmp.

>
> >> I disagree. The similarity is too uncanny to not be related. As C++
> >> was designed to formalize and build upon existing C practices, it
> >> makes sense.

>
> >>> setjmp/longjmp is essentially a non-local goto.
> >>> It is not an exception, nor does it unwind the stack, it simply
> >>> overwrites the stack pointer.

>
> >> No one was suggesting anything of the sort. I'll excuse your
> >> miscomprehension of what I wrote only if English is not your primary
> >> language. (Because I'm tired of all the childish antics in
> >> programming forums).

>
> > I believe you told us that you had read "The Design and Evolution of
> > C+ +" by Stroustrup. If that was the case, you'd be aware of the
> > origin of the C++ exception mechanism. The origin is Ada, and the
> > belief that a try-block executes anything similar to a setjmp or that
> > a catch executes anything similar to a longjmp is misleading and
> > wrong.

>
> The pattern is the same. No one suggested that the _mechanisms_ were the
> same or even alike. "Jumping across levels" is jumping across levels.


They're not. You have to manually jump back and forth with longjmp,
that is at least a round trip to free resources. Exception handling is
a one way trip. That's fundamentally different. Perhaps they both
serve a similar purpose, but they "get there" in very different ways.
Reply With Quote
  #112 (permalink)  
Old 12-09-2009, 09:16 AM
dragan
Guest
 
Posts: n/a
Default Re: Why do some code bases don't use exceptions?

Joshua Maurice wrote:
> On Dec 9, 1:44 am, "dragan" <spambus...@prodigy.net> wrote:
>> peter koch wrote:
>>> On 8 Dec., 22:15, "dragan" <spambus...@prodigy.net> wrote:
>>>> "Richard" <legalize+jee...@mail.xmission.com> wrote in message

>>
>>> [snip]

>>
>>>>> (setjmp/longjmp vs. C++
>>>>> exceptions), not the more advanced. C++ exceptions are in no way
>>>>> derived from setjmp.

>>
>>>> I disagree. The similarity is too uncanny to not be related. As C++
>>>> was designed to formalize and build upon existing C practices, it
>>>> makes sense.

>>
>>>>> setjmp/longjmp is essentially a non-local goto.
>>>>> It is not an exception, nor does it unwind the stack, it simply
>>>>> overwrites the stack pointer.

>>
>>>> No one was suggesting anything of the sort. I'll excuse your
>>>> miscomprehension of what I wrote only if English is not your
>>>> primary language. (Because I'm tired of all the childish antics in
>>>> programming forums).

>>
>>> I believe you told us that you had read "The Design and Evolution of
>>> C+ +" by Stroustrup. If that was the case, you'd be aware of the
>>> origin of the C++ exception mechanism. The origin is Ada, and the
>>> belief that a try-block executes anything similar to a setjmp or
>>> that a catch executes anything similar to a longjmp is misleading
>>> and wrong.

>>
>> The pattern is the same. No one suggested that the _mechanisms_ were
>> the same or even alike. "Jumping across levels" is jumping across
>> levels.

>
> They're not.


I didn't say 'they', I said 'the': the pattern defined as propagating across
levels as compared to propagating one activation record at a time. That is
THE key behavior of C++ exception machinery, hence the focus on that and
what I thought would have been obvious contextually given the topic (I guess
not!). Read the whole passage again and you will surely understand it as
what I reframed if you don't whittle out a portion of it and react only to
that portion.

> You have to manually jump back and forth with longjmp,
> that is at least a round trip to free resources. Exception handling is
> a one way trip. That's fundamentally different. Perhaps they both
> serve a similar purpose, but they "get there" in very different ways.



Reply With Quote
  #113 (permalink)  
Old 12-09-2009, 05:39 PM
Paavo Helde
Guest
 
Posts: n/a
Default Re: Why do some code bases don't use exceptions?

"dragan" <spambuster@prodigy.net> wrote in
news:gOKTm.18454$y%5.5032@newsfe03.iad:

> Joshua Maurice wrote:
>> On Dec 9, 1:44 am, "dragan" <spambus...@prodigy.net> wrote:
>>> peter koch wrote:

....
>>>> I believe you told us that you had read "The Design and Evolution
>>>> of C+ +" by Stroustrup. If that was the case, you'd be aware of the
>>>> origin of the C++ exception mechanism. The origin is Ada, and the
>>>> belief that a try-block executes anything similar to a setjmp or
>>>> that a catch executes anything similar to a longjmp is misleading
>>>> and wrong.
>>>
>>> The pattern is the same. No one suggested that the _mechanisms_ were
>>> the same or even alike. "Jumping across levels" is jumping across
>>> levels.

>>
>> They're not.

>
> I didn't say 'they', I said 'the': the pattern defined as propagating
> across levels as compared to propagating one activation record at a
> time.


But this is exactly what happens when an exception is thrown: each call
stack frame is processed, one at a time, and all automatic objects
destroyed properly. You have to invent something else if you still want to
argue that longjmp and exceptions are essentially the same.

Paavo
Reply With Quote
  #114 (permalink)  
Old 12-10-2009, 06:03 AM
dragan
Guest
 
Posts: n/a
Default Re: Why do some code bases don't use exceptions?

Paavo Helde wrote:
> "dragan" <spambuster@prodigy.net> wrote in
> news:gOKTm.18454$y%5.5032@newsfe03.iad:
>
>> Joshua Maurice wrote:
>>> On Dec 9, 1:44 am, "dragan" <spambus...@prodigy.net> wrote:
>>>> peter koch wrote:

> ...
>>>>> I believe you told us that you had read "The Design and Evolution
>>>>> of C+ +" by Stroustrup. If that was the case, you'd be aware of
>>>>> the origin of the C++ exception mechanism. The origin is Ada, and
>>>>> the belief that a try-block executes anything similar to a setjmp
>>>>> or that a catch executes anything similar to a longjmp is
>>>>> misleading and wrong.
>>>>
>>>> The pattern is the same. No one suggested that the _mechanisms_
>>>> were the same or even alike. "Jumping across levels" is jumping
>>>> across levels.
>>>
>>> They're not.

>>
>> I didn't say 'they', I said 'the': the pattern defined as propagating
>> across levels as compared to propagating one activation record at a
>> time.

>
> But this is exactly what happens when an exception is thrown: each
> call stack frame is processed, one at a time, and all automatic
> objects destroyed properly. You have to invent something else if you
> still want to argue that longjmp and exceptions are essentially the
> same.
>


You fail to recognize that I never said anything of the sort. Stop wasting
my time thank you.


Reply With Quote
  #115 (permalink)  
Old 12-10-2009, 08:32 AM
Nick Keighley
Guest
 
Posts: n/a
Default Re: Why do some code bases don't use exceptions?

On 25 Nov, 16:28, legalize+jee...@mail.xmission.com (Richard) wrote:
> peter koch <peter.koch.lar...@gmail.com> spake the secret code
> <99e979fd-651c-4a27-a72a-d3eab8bd9...@e27g2000yqd.googlegroups.com> thusly:


[why exceptions?]

> >int func(parm p,std::string &result)
> >{
> > * *std::string s;
> > * *int error;

>
> > * *result = func_1(parm,s);
> > * *if (error != OK)
> > * *{
> > * * * *return error;
> > * *}
> > * *error = func_2(s);
> > * *if (error != OK)
> > * *{
> > * * * *return error;
> > * *}
> > * *result = s;
> > * *return OK;
> >}

>
> >instead of the much simpler

>
> >std::string func(parm)
> >{
> > * *return func_2(func_1(parm));
> >}

>
> This sort of code is profusely present in code that uses COM because
> every method on a COM interface typically returns an HRESULT status
> code that you should check.


it's the C way there's loads of stuff that works like that. Embedded
SQL, sockets, Win32. Every function returns an error code and you have
to check it.

Result db_update_box_title (Box_id id, const char *title)
{
Box_data data;
Db_conn connection = db_get_connection();
if (connection == NULL)
return E_CANT_CONNECT;

db_read_box (id, &data);
CHECK_DB;

strcpy (data.title, title);

db_write_box (id, &data);
CHECK_DB;
}

Where CHECK_DB did something like

if ((result = sql_error()) != SQL_OK)
return result;

this was actually a concious effort to emulate exceptions. The code
could have been far nastier!

> There are three ways I've seen people deal with such error codes:
> - ignore them and pretend errors never happen (bad code)


oh yes! At least they have write extra code to ignore exceptions!


> - inline handling as above (hard to read code)
>
> - map HRESULTs to exceptions and handle them at the appropriate
> * boundaries (throwing a C++ exception is undefined when implementing
> * a COM object, so you have to catch and bubble out HRESULTs)
>
> The latter is the approach I have been teaching for almost 10+ years
> now and it dramatically simplifies writing and understanding such
> code.

Reply With Quote
 
Reply

Popular Tags in the Forum
bases, code, exceptions

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 06:53 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.