Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Question about catch

Reply
Thread Tools

Question about catch

 
 
cwc5w@hotmail.com
Guest
Posts: n/a
 
      12-20-2006
int main()
{
try {
b();
} catch(...) {
return 1;
} catch(int i) {
return 2;
}

what ll happen to this code?
does it always generate syntax error because of the catch(...) phase?
or is it complier specific?

Thanks!

 
Reply With Quote
 
 
 
 
Andre Kostur
Guest
Posts: n/a
 
      12-20-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:1166606607.464543.229260
@t46g2000cwa.googlegroups.com:

> int main()
> {
> try {
> b();
> } catch(...) {
> return 1;
> } catch(int i) {
> return 2;
> }
>
> what ll happen to this code?
> does it always generate syntax error because of the catch(...) phase?
> or is it complier specific?


The Standard (s15.3.6) says that the catch(...) "shall be the last handler
for its try block". (Oh, and I'm assuming that you have one more '}' to
close the main() block)
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      12-20-2006
(E-Mail Removed) wrote:
> int main()
> {
> try {
> b();
> } catch(...) {
> return 1;
> } catch(int i) {
> return 2;
> }
>

missing }

> does it always generate syntax error because of the catch(...) phase?
> or is it complier specific?
>

catch(...) must be last, it doesn't make sense any other way.


--
Ian Collins.
 
Reply With Quote
 
cwc5w@hotmail.com
Guest
Posts: n/a
 
      12-20-2006
thanks for the quick reply!
yes, typo on the "}"

 
Reply With Quote
 
Anant
Guest
Posts: n/a
 
      12-20-2006
I think, it will not be compiler dependent.

Because at run time, we check all the catch blocks sequentially, and as
soon as we find datatype of exception and catch block are same , we
just ignore rest others.

And once catch(...) is found it means you will never check for other
catch blocks. So all compiler will be forcing to write catch(...) in
the last only.


(E-Mail Removed) wrote:
> int main()
> {
> try {
> b();
> } catch(...) {
> return 1;
> } catch(int i) {
> return 2;
> }
>
> what ll happen to this code?
> does it always generate syntax error because of the catch(...) phase?
> or is it complier specific?
>
> Thanks!


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
catch doesn't catch a thrown exception Marteno Rodia Java 5 08-05-2009 03:30 AM
catch(...) doesn't catch everything Adam C++ 9 02-02-2006 05:02 PM
why catch (...) can not catch such exception John Black C++ 8 08-20-2004 02:34 PM
J2ME question:how i can catch command event Sveta Java 1 02-29-2004 09:15 PM
Question: Try,Catch,Finally VB Programmer ASP .Net 1 08-07-2003 07:27 PM



Advertisments