C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Question about catch

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed Dec 20, 2006 10:10 am    Post subject: Question about catch Reply with quote



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!
Back to top
Andre Kostur
Guest





PostPosted: Wed Dec 20, 2006 10:10 am    Post subject: Re: Question about catch Reply with quote



cwc5w (AT) hotmail (DOT) com wrote in news:1166606607.464543.229260
@t46g2000cwa.googlegroups.com:

Quote:
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)
Back to top
Ian Collins
Guest





PostPosted: Wed Dec 20, 2006 10:10 am    Post subject: Re: Question about catch Reply with quote



cwc5w (AT) hotmail (DOT) com wrote:
Quote:
int main()
{
try {
b();
} catch(...) {
return 1;
} catch(int i) {
return 2;
}

missing }


Quote:
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.
Back to top
Guest






PostPosted: Wed Dec 20, 2006 10:10 am    Post subject: Re: Question about catch Reply with quote

thanks for the quick reply!
yes, typo on the "}"
Back to top
Anant
Guest





PostPosted: Wed Dec 20, 2006 10:10 am    Post subject: Re: Question about catch Reply with quote

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.


cwc5w (AT) hotmail (DOT) com wrote:
Quote:
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!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.