Question about catch



 DEVELOP > c-Plus-Plus > Question about catch

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 20 Dec 2006 03:23:27 AM
Object: Question about catch
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!
.

User: "Andre Kostur"

Title: Re: Question about catch 20 Dec 2006 03:32:46 AM
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)
.

User: "Ian Collins"

Title: Re: Question about catch 20 Dec 2006 03:35:23 AM
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.
.

User: "Anant"

Title: Re: Question about catch 20 Dec 2006 03:43:43 AM
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@hotmail.com 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!

.

User: ""

Title: Re: Question about catch 20 Dec 2006 03:38:31 AM
thanks for the quick reply!
yes, typo on the "}"
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER