473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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!

Dec 20 '06 #1
4 1015
cw***@hotmail.com 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)
Dec 20 '06 #2
cw***@hotmail.com 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.
Dec 20 '06 #3
thanks for the quick reply!
yes, typo on the "}"

Dec 20 '06 #4
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.
cw***@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!
Dec 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Mark | last post by:
Apologies for the lengthy posting.... In a previous posting:...
5
by: Kevin Jackson | last post by:
In the following code snippet, will the finally block be executed when the throw is executed in the catch block???? I'm assuming it will. catch (Exception e) { // if...
1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
2
by: ETL | last post by:
Hi, I think this question has an easy answer but I can't seem to find anything online that lists best practices for my problem. I have a C# app that uses an exception handling tree similar to...
13
by: Woody Splawn | last post by:
I have a try catch statement in a fucntion that is supposed to return a true or a false My code looks like this: Try mySqlConnection.Open() Dim Da1 As New SqlDataAdapter("Select JnlType,...
7
by: Tiraman | last post by:
Hi , I am using allot the try catch in my code and the question is if it is good ? it will decrease my performance ? one more question
5
by: Patrick Dickey | last post by:
Hello, All! I'm modifying some source code that I downloaded from Planet-source-code a while back, and have a question about Try Catch statements. Basically, I'm wondering if I can do a Try with...
10
by: tony | last post by:
Hello!! As you know every user defined exception must be derived from class Exception. Now to my question if I write catch then every exception will be caught. If I instead write...
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
5
by: Vijay | last post by:
Hi All, I am not able to figure out what exactly happening in below code. what is control flow. Can anyone clear my confusion? Code: class A { public: A(){cout<<"In Constructor\n";}
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.