473,403 Members | 2,293 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,403 software developers and data experts.

try--catch inside do...while

AB
Hi All,

I've got a section of code which resembles

do
{
try...........(1)
{
//do something here
}
catch(exception)
{
//handle exception
}
}
while(condition) ;

//resume execution............(2)

If the exception is not thrown, the loop continues normally. However,
when an exception is caught...the catch block is executed after which
control moves to (2) and not back to (1) as I expected.

Can anyone tell me what I'm missing out here? If it helps...I'm using
the MSVC 8.0 compiler.

Jun 2 '06 #1
2 4640
AB wrote:
I've got a section of code which resembles

do
{
try...........(1)
{
//do something here
}
catch(exception)
{
//handle exception
}
}
while(condition) ;

//resume execution............(2)

If the exception is not thrown, the loop continues normally. However,
when an exception is caught...the catch block is executed after which
control moves to (2) and not back to (1) as I expected.
What's the "condition" if the exception is thrown?
Can anyone tell me what I'm missing out here? If it helps...I'm using
the MSVC 8.0 compiler.


It doesn't help. If you need compiler-specific information, post to
the VC++ newsgroup: 'microsoft.public.vc.language'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 2 '06 #2
AB <ab*****@gmail.com> wrote:
I've got a section of code which resembles

do
{
try...........(1)
{
//do something here
}
catch(exception)
{
//handle exception
}
}
while(condition) ;

//resume execution............(2)

If the exception is not thrown, the loop continues normally. However,
when an exception is caught...the catch block is executed after which
control moves to (2) and not back to (1) as I expected.


What happens when you run this program?
#include <iostream>

int main()
{
int i = 0;

do {
try {
std::cout << "i = " << i << '\n';
++i;
if (i == 2) {
throw 2;
}
}
catch (int e) {
std::cout << "caught " << e << '\n';
}
} while (i < 4);
}
Using MSVC 7.1 my output is:

i = 0
i = 1
caught 2
i = 2
i = 3

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jun 2 '06 #3

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

Similar topics

2
by: Aggelos | last post by:
Hi Guys!!! Thanks in advance for any kind of help about this problem. The problem: Acces Database One Table 'Orders' and second 'OrderItems' I want to export in txt file using FSO and...
3
by: .Net Sports | last post by:
I want to include some asp if statements inside a do until loop, predicated on the recordset going until EOF. I do not have any < % %> delimiters inside the include file. The below doesnt show the...
36
by: invni | last post by:
I have a nested while. How do I go from the inner while to the beginning of the outer while? Can this be done without using goto? while_1() { some codes here while_2() { if true go to the...
147
by: Michael B Allen | last post by:
Should there be any preference between the following logically equivalent statements? while (1) { vs. for ( ;; ) { I suspect the answer is "no" but I'd like to know what the consensus is
5
by: Roy Smith | last post by:
The following code appears to be illegal: while ((int c = getchar()) != EOF) { putchar (c); } I tried it on two different compilers (Sun workshop and gcc), and both give some variation on...
9
by: Cybex | last post by:
I am trying to get this to work but when ever I enter an proper integer it just hangs. The Switch default seems to catch the improper integers but the right ones are not triggering the way I...
1
by: Prabhua | last post by:
hi all, can anybody solve my probelm in asp.net using c#. i am creating button inside while loop at runtime in html page.i just want to give different ID for different button inside while...
10
by: rohitjogya | last post by:
Can anyone tell me the difference bet for loop and while loop execution? ____________________ for (i=0 ; i<10 ; i++) ; /* Do nothing*/ print i; ___________________ i=0;
9
by: somenath | last post by:
Hi All, I have doubt regarding how compiler understands about while loop. For example the bellow mentioned code produce the output as mentioned bellow. #include<stdio.h> int main(void) {
9
by: saravanan82 | last post by:
Hi All, I tried to execute follwoing program, which got killed by the OS. #include<stdlib.h> main() { while(1) { char *c=(char*)malloc(10000); } }
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.