[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Positioning of catch(...

Taras_96

10/13/2008 9:20:00 AM

Hi everyone,

I recently came across a quiz question. Does the standard say anything
about catch(...) being the first catch statement?

try
{
}
catch(...) // <- 'hides' subsequent catching
{
}
catch(A)
{
}
catch(B)
{
}

I've seen numerous examples where catch(...) appears first (eg:
Bjorne), but code doesn't compile using MS C++, so does this mean that
the standard allows it, but some compilers don't?

Taras
11 Answers

Kai-Uwe Bux

10/13/2008 9:28:00 AM

0

Taras_96 wrote:

> Hi everyone,
>
> I recently came across a quiz question. Does the standard say anything
> about catch(...) being the first catch statement?

Yes, catch statements are tried in order [15.3/5] and if present, a
catch(...) shall go last.


> try
> {
> }
> catch(...) // <- 'hides' subsequent catching
> {
> }
> catch(A)
> {
> }
> catch(B)
> {
> }
>
> I've seen numerous examples where catch(...) appears first (eg:
> Bjorne), but code doesn't compile using MS C++, so does this mean that
> the standard allows it, but some compilers don't?

The standard says [15.3/6]:

A ... in a handler?s exception-declaration functions similarly to ... in a
function parameter declaration; it specifies a match for any exception. If
present, a ... handler shall be the last handler for its try block.

That says that a program where catch(...) is not the last handler in a block
is ill-formed ("shall").


Best

Kai-Uwe Bux

Pranav

10/13/2008 12:14:00 PM

0

On Oct 13, 2:28 pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
> Taras_96 wrote:
> > Hi everyone,
>
> > I recently came across a quiz question. Does the standard say anything
> > about catch(...) being the first catch statement?
>
> Yes, catch statements are tried in order [15.3/5] and if present, a
> catch(...) shall go last.
>
>
>
> > try
> > {
> > }
> > catch(...) // <- 'hides' subsequent catching
> > {
> > }
> > catch(A)
> > {
> > }
> > catch(B)
> > {
> > }
>
> > I've seen numerous examples where catch(...) appears first (eg:
> > Bjorne), but code doesn't compile using MS C++, so does this mean that
> > the standard allows it, but some compilers don't?
>
> The standard says [15.3/6]:
>
>   A ... in a handler?s exception-declaration functions similarly to ... in a
>   function parameter declaration; it specifies a match for any exception. If
>   present, a ... handler shall be the last handler for its try block.
>
> That says that a program where catch(...) is not the last handler in a block
> is ill-formed ("shall").
>
> Best
>
> Kai-Uwe Bux

From Wheer can I get C++ standard or it is just Bjarne Strostrup CPP
book..,

Jeff Schwab

10/13/2008 2:08:00 PM

0

Pranav wrote:
> From Wheer can I get C++ standard or it is just Bjarne Strostrup CPP
> book..,

http://www.parashift.com/c++-faq-lite/big-picture.htm...

Juha Nieminen

10/13/2008 4:36:00 PM

0

Kai-Uwe Bux wrote:
> That says that a program where catch(...) is not the last handler in a block
> is ill-formed ("shall").

What does "ill-formed" mean in practice? Does it have something to do
with "undefined behavior"?

Erik Wikström

10/13/2008 4:40:00 PM

0

On 2008-10-13 18:36, Juha Nieminen wrote:
> Kai-Uwe Bux wrote:
>> That says that a program where catch(...) is not the last handler in a block
>> is ill-formed ("shall").
>
> What does "ill-formed" mean in practice? Does it have something to do
> with "undefined behavior"?

I believe that ill-formed code is not required to compile, while
undefined behaviour refers to the run-time behaviour (which means that
the code did compile).

--
Erik Wikström

James Kanze

10/13/2008 5:12:00 PM

0

On Oct 13, 6:39 pm, Erik Wikström <Erik-wikst...@telia.com> wrote:
> On 2008-10-13 18:36, Juha Nieminen wrote:

> > Kai-Uwe Bux wrote:
> >> That says that a program where catch(...) is not the last
> >> handler in a block is ill-formed ("shall").

> > What does "ill-formed" mean in practice? Does it have
> > something to do with "undefined behavior"?

> I believe that ill-formed code is not required to compile,
> while undefined behaviour refers to the run-time behaviour
> (which means that the code did compile).

Sort of. Ill-formed means that the compiler must issue a
diagnostic. Having done so, it is free to compile the code if
it wishes. (Good compilers generally don't.) Undefined
behavior means just that---whatever the compiler does with the
code is correct as far as the standard is concerned. It may
refuse to compile it (with or without an error message); it may
compile it do something that works; or it may compile it to do
anything else.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

ozarkheart

12/19/2012 1:31:00 AM

0

On Tue, 18 Dec 2012 17:27:36 +0000 (UTC), Matt
<matttelles@sprynet.com> wrote:

>BroilJAB <DesignDenier@wmconnect.com> wrote in news:47152e46-fe4d-454a-
>ac8b-3d2de1f6a486@u13g2000vbc.googlegroups.com:
>
>> Obama: Use This Tragedy to Take Bill of Rights
>> Already Obama has pardoned thousands of Black
>> killers, rapists like threw the woman under the train.
>> Now, he is on record "We will use school shooting
>> to take away the Bill of Rights."
>>
>> If you do not now own a magnum pistol, buy one.
>> Use it for Bill of Rights self-defense solely.
>>
>
>In fact, we are using this crisis to round all of you up and have you put
>into camps.
>
>That knock on your door is us.

Sadly it could cery well end up that way....

Matt

12/19/2012 4:59:00 PM

0

ozarkheart@yahoo.com wrote in
news:3662d85jpvuotcm39d008hvftqkum955gp@4ax.com:

> On Tue, 18 Dec 2012 17:27:36 +0000 (UTC), Matt
> <matttelles@sprynet.com> wrote:
>
>>BroilJAB <DesignDenier@wmconnect.com> wrote in
>>news:47152e46-fe4d-454a-
>>ac8b-3d2de1f6a486@u13g2000vbc.googlegroups.com:
>>
>>> Obama: Use This Tragedy to Take Bill of Rights
>>> Already Obama has pardoned thousands of Black
>>> killers, rapists like threw the woman under the train.
>>> Now, he is on record "We will use school shooting
>>> to take away the Bill of Rights."
>>>
>>> If you do not now own a magnum pistol, buy one.
>>> Use it for Bill of Rights self-defense solely.
>>>
>>
>>In fact, we are using this crisis to round all of you up and have you
>>put into camps.
>>
>>That knock on your door is us.
>
> Sadly it could cery well end up that way....
>

For him? Yes, I suspect it will. They don't allow guns in the rubber rooms.

Matt

Dänk 42Ø

12/19/2012 6:40:00 PM

0

On 12/18/2012 05:27 PM, Matt wrote:
> BroilJAB <DesignDenier@wmconnect.com> wrote in news:47152e46-fe4d-454a-
> ac8b-3d2de1f6a486@u13g2000vbc.googlegroups.com:
>
>> Obama: Use This Tragedy to Take Bill of Rights
>> Already Obama has pardoned thousands of Black
>> killers, rapists like threw the woman under the train.
>> Now, he is on record "We will use school shooting
>> to take away the Bill of Rights."
>>
>> If you do not now own a magnum pistol, buy one.
>> Use it for Bill of Rights self-defense solely.
>>
>
> In fact, we are using this crisis to round all of you up and have you put
> into camps.
>
> That knock on your door is us.

People like you were what the Framers had in mind when they wrote
the 2nd Amendment.

I prefer to live in an imperfect but free society rather than the
perfect socialist utopia you advocate where Big Shepherd keeps his
sheep safely confined in pens and keeps them well-fed until they are
ready to be slaughtered. People are free, sheep are not. Sheep
are unarmed.



= = = = = = = = = = = = = = = = = = = = = = = = = = == = = = = = = = =

'Boxer has fallen! He is lying on his side and can't get up!'

'It is my lung,' said Boxer in a weak voice. 'It does not matter. I
think you will be able to finish the windmill without me. There is a
pretty good store of stone accumulated. I had only another month to go
in any case. To tell you the truth I had been looking forward to my
retirement. And perhaps, as Benjamin is growing old too, they will let
him retire at the same time and be a companion to me.'

For the next two days Boxer remained in his stall. ... Boxer professed
not to be sorry for what had happened. If he made a good recovery he
might expect to live another three years, and he looked forward to the
peaceful days that he would spend in the corner of the big pasture.

It was in the middle of the day when the van came to take him away.
'Quick, quick! Come at once! They're taking Boxer away!' The animals
crowded round the van. 'Good-bye, Boxer!' they chorused, 'good-bye!'

'Fools! Fools!' shouted Benjamin, prancing round them and stamping the
earth with his small hoofs. 'Fools! Do you not see what is written on
the side of that van?'

That gave the animals pause, and there was a hush. Muriel began to
spell out the words. But Benjamin pushed her aside and in the midst of
a deadly silence he read: '"Alfred Simmonds, Horse Slaughterer and
Glue Boiler, Willingdon. Dealer in Hides and Bone-Meal. Kennels
Supplied." Do you not understand what that means? They are taking
Boxer to the knacker's!'

'Boxer!' cried Clover in a terrible voice. 'Boxer! Get out! Get out
quickly! They are taking you to your death!'

On the day appointed for the [memorial] banquet a grocer's van drove
up from Willingdon and delivered a large wooden crate at the farmhouse.
That night there was the sound of uproarious singing, which was
followed by what sounded like a violent quarrel and ended at about
eleven o'clock with a tremendous crash of glass. No one stirred in the
farmhouse before noon on the following day. And the word went round
that from somewhere or other the pigs had acquired the money to buy
themselves another case of whisky.

-- 1984

Dänk 42Ø

12/19/2012 6:41:00 PM

0

On 12/19/2012 04:59 PM, Matt wrote:
> ozarkheart@yahoo.com wrote in
> news:3662d85jpvuotcm39d008hvftqkum955gp@4ax.com:
>
>> On Tue, 18 Dec 2012 17:27:36 +0000 (UTC), Matt
>> <matttelles@sprynet.com> wrote:
>>
>>> BroilJAB <DesignDenier@wmconnect.com> wrote in
>>> news:47152e46-fe4d-454a-
>>> ac8b-3d2de1f6a486@u13g2000vbc.googlegroups.com:
>>>
>>>> Obama: Use This Tragedy to Take Bill of Rights
>>>> Already Obama has pardoned thousands of Black
>>>> killers, rapists like threw the woman under the train.
>>>> Now, he is on record "We will use school shooting
>>>> to take away the Bill of Rights."
>>>>
>>>> If you do not now own a magnum pistol, buy one.
>>>> Use it for Bill of Rights self-defense solely.
>>>>
>>>
>>> In fact, we are using this crisis to round all of you up and have you
>>> put into camps.
>>>
>>> That knock on your door is us.
>>
>> Sadly it could cery well end up that way....
>>
>
> For him? Yes, I suspect it will. They don't allow guns in the rubber rooms.

Soviets didn't allow guns anywhere, except in the hands of the secret
police.