try-catch name

W

White Wolf

Hi,

I cannot believe my eyes, but so far I could not find out what is the name
of the construct, which is built from one try block and the catch clauses
(handlers). I am not looking for a grammar name, but something people can
remember, like handler. But is not handler, because those are the catch
clauses and the try does not belong there. I have looked at all my books
and the standard, but I could not find a name. :-(

Is there anyone who knows that name? If there is, please share it with me
here. :)
 
G

GB

White said:
Hi,

I cannot believe my eyes, but so far I could not find out what is the name
of the construct, which is built from one try block and the catch clauses
(handlers). I am not looking for a grammar name, but something people can
remember, like handler. But is not handler, because those are the catch
clauses and the try does not belong there. I have looked at all my books
and the standard, but I could not find a name. :-(

Is there anyone who knows that name? If there is, please share it with me
here. :)

It's called a try statement.

Gregg
 
W

White Wolf

GB said:
It's called a try statement.

Thanks. Could you tell me where can this be found? I have tried to find
"try statement" in the standard, in The C++ Programming Language Spec.
Edition and even Google.

As far as I can see the try statement is not used by C++ literature (it is
used in C# and Python), or where it is used it is used either as the synonim
for the try keyword or the try expression, none of which contains the whole
try-and-all-catch thing. That is why I have asked for source of
information, I cannot seem to find it.
 
G

GB

White said:
Thanks. Could you tell me where can this be found? I have tried to find
"try statement" in the standard, in The C++ Programming Language Spec.
Edition and even Google.
As far as I can see the try statement is not used by C++ literature (it is
used in C# and Python), or where it is used it is used either as the synonim
for the try keyword or the try expression, none of which contains the whole
try-and-all-catch thing. That is why I have asked for source of
information, I cannot seem to find it.

Well I have to admit, I looked (albeit briefly) and couldn't find a
definite answer either. That's just how I would refer to it. The grammar
treats the try-block as a statement and the catch handler as a
statement, but it is a semantic error to have one without the other, so
the whole construct would appear to me to be a statement. It is
certainly true that the whole construct can be used as one. For example:

if (cond)
try {
}
catch (...) {
}

I think maybe the standard calls the whole construct an exception
handler, which consists of a try clause and a catch clause.

Gregg
 
G

GB

White said:
Thanks. Could you tell me where can this be found? I have tried to find
"try statement" in the standard, in The C++ Programming Language Spec.
Edition and even Google.

As far as I can see the try statement is not used by C++ literature (it is
used in C# and Python), or where it is used it is used either as the synonim
for the try keyword or the try expression, none of which contains the whole
try-and-all-catch thing. That is why I have asked for source of
information, I cannot seem to find it.

Well I have to admit, I looked (albeit briefly) and couldn't find a
definite answer either. That's just how I would refer to it. The grammar
treats the try-block itself as a statement, but it would be a semantic
error to have the try-block without one or more matching catch clauses,
so the whole construct would appear to me to be a statement. It is
certainly true that the whole construct can be used as one. For example:

if (cond)
try {
}
catch (const myexc&) {
}
catch (...) {
}

I think actually the standard calls the whole construct an exception
handler, which consists of a try clause and a catch clause.

Gregg
 
G

GB

White said:
Thanks. Could you tell me where can this be found? I have tried to find
"try statement" in the standard, in The C++ Programming Language Spec.
Edition and even Google.

As far as I can see the try statement is not used by C++ literature (it is
used in C# and Python), or where it is used it is used either as the synonim
for the try keyword or the try expression, none of which contains the whole
try-and-all-catch thing. That is why I have asked for source of
information, I cannot seem to find it.

Well I have to admit, I looked (albeit briefly) and couldn't find a
definite answer either. That's just how I would refer to it. The grammar
treats the try-block itself as a statement, but it would be a semantic
error to have the try-block without one or more matching catch clauses,
so the whole construct would appear to me to be a statement. It is
certainly true that the whole construct can be used as one. For example:

if (cond)
try {
}
catch (const myexc&) {
}
catch (...) {
}

I think actually the standard calls the whole construct an exception
handler, which consists of a try clause and one or more catch clauses.

Gregg
 
G

GB

GB said:
I think actually the standard calls the whole construct an exception
handler, which consists of a try clause and one or more catch clauses.

For example, in section 1.3.9, it refers to the "catch clause of an
exception handler".

Gregg
 
W

White Wolf

GB said:
For example, in section 1.3.9, it refers to the "catch clause of an
exception handler".

Thank you for the help!

I think that the confusion is then complete. :) C++ Primer excusively
calls the catch clauses handlers, and so does the grammar. So I guess I
have to call it try-catch or try&catch until a better name comes along. I
would just allow room for ambiguity with either (otherwise good) name. :-(
 
A

Alf P. Steinbach

* White Wolf:
Thank you for the help!

I think that the confusion is then complete. :) C++ Primer excusively
calls the catch clauses handlers, and so does the grammar. So I guess I
have to call it try-catch or try&catch until a better name comes along. I
would just allow room for ambiguity with either (otherwise good) name. :-(

How about "try-catch statement"?

Just ignore the darned standard, it's very non-standard (heh) in its
terminology...
 
W

White Wolf

Alf said:
* White Wolf:

How about "try-catch statement"?

I will probably use that where it fits (I admit I make slides ;-)).
Just ignore the darned standard, it's very non-standard (heh) in its
terminology...

:) When I will be in the position that enables me to create C++ technical
terminology, I will certainly do that. Until then, I should stick with what
serves my target audience best.
 
G

GB

White said:
Thank you for the help!

I think that the confusion is then complete. :) C++ Primer excusively
calls the catch clauses handlers, and so does the grammar. So I guess I
have to call it try-catch or try&catch until a better name comes along. I
would just allow room for ambiguity with either (otherwise good) name. :-(

I see I was mistaken when I said that the grammar treats the try part
alone as a statement. The grammar uses the term try-block to refer to
the whole construct, including the catch clauses, not just the try part.
However, both the standard and Stroustrup's book use the term "try
block" to refer to the try part alone. For example, at the end of page
187, he says "If any code in a try block - or called from it - throws an
exception, the try block's handlers will be examined." However, this is
not literally true if the exception handlers themselves are considered
part of the try block.

Gregg
 
W

White Wolf

GB wrote:
[SNIP]
I see I was mistaken when I said that the grammar treats the try part
alone as a statement. The grammar uses the term try-block to refer to
the whole construct, including the catch clauses, not just the try part.
However, both the standard and Stroustrup's book use the term "try
block" to refer to the try part alone. For example, at the end of page
187, he says "If any code in a try block - or called from it - throws an
exception, the try block's handlers will be examined." However, this is
not literally true if the exception handlers themselves are considered
part of the try block.

Yep, there seems to be a bit of confusion around the terminology. :-(
 
W

White Wolf

Ron said:
Actually the terminonlogy in the standard is "try-block"
(which is a statement).

As far as I saw that only covers the try part, but not the handlers. At
least according to the grammar part, and according to C++ Primer 3rd
edition.
 
R

Ron Natalie

White said:
As far as I saw that only covers the try part, but not the handlers. At
least according to the grammar part, and according to C++ Primer 3rd
edition.
Nope, it covers everything. try-block is "try compound-statement handler-seq".
 
W

White Wolf

Ron said:
Nope, it covers everything. try-block is "try compound-statement
handler-seq".

Right. How did I miss that one? In this case I just hope C++ Primer 4th
edition has actually fixed the misuse of the term. Since in their
"free-to-access" chapter 11 it says:

'A try block introduces a local scope, and variables declared within a try
block cannot be referred to outside the try block, including within the
catch clauses.'

I mean that makes it pretty clear that the author(s) did not count the
handlers into the try block. I just wonder how did I manage to
misunderstand the standard. Maybe it was the tiredness.

Thanks Ron!
 
A

Andrew Koenig

I cannot believe my eyes, but so far I could not find out what is the name
of the construct, which is built from one try block and the catch clauses
(handlers). I am not looking for a grammar name, but something people can
remember, like handler. But is not handler, because those are the catch
clauses and the try does not belong there. I have looked at all my books
and the standard, but I could not find a name. :-(

Is there anyone who knows that name? If there is, please share it with me
here. :)

The C++ standard uses the term "try-block" to refer to the entire statement,
including all handlers, and does not appear to have a separate name for the
compound statement that appears between "try" and the first "catch."

I had to look at the standard to find this out. Left to my own devices, I
would have used "try statement" to refer to the entire statement and
"subject of the try statement" to refer to the compound statement between
"try" and "catch."
 
A

Alexander Terekhov

Andrew Koenig wrote:
[...]
I had to look at the standard to find this out. Left to my own devices, I
would have used "try statement" to refer to the entire statement and
"subject of the try statement" to refer to the compound statement between
"try" and "catch."

Nah, in the case of function-try-block, "try-body" consists from
ctor-initializer (opt) and function-body (compound-statement).

And {function-}try-block's handler-seq is nothing but one or more
legs supporting the body, oder? ;-)

regards,
alexander.
 
W

White Wolf

Andrew said:
The C++ standard uses the term "try-block" to refer to the entire
statement, including all handlers, and does not appear to have a
separate name for the compound statement that appears between "try" and
the first "catch."
I had to look at the standard to find this out. Left to my own devices,
I would have used "try statement" to refer to the entire statement and
"subject of the try statement" to refer to the compound statement between
"try" and "catch."

Thanks. These names actually do make a lot of sense. I mean the "subject
of the try statement" states very nicely/clearly the purpose of that part.
I think I am going to make an update of my course material.
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top