473,396 Members | 1,797 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,396 software developers and data experts.

exception throw and handle and resume

Hi Everyone,

I have the following code,

int main()
{
bool continue1 = true;
while(continue1)
{
try
{
printf("executed\n");
throw 5;
continue1 = false;
}
catch(int)
{
printf("exception caught, and about to retry also\n");
continue1 = true;
}
}
return(0);
}

So it turns out to be a recursive throw and handling of the integer
exception. the int 5 is allocated in the stack and therefore i assume
that it is passed to the catch handler by value as a function call...
if that is the case, is it similar to recursive function call and
would cause a stack overflow?

Thanks in advance!!!
Dec 8 '07 #1
4 1863
Rahul wrote:
Hi Everyone,

I have the following code,

int main()
{
bool continue1 = true;
while(continue1)
{
try
{
printf("executed\n");
throw 5;
continue1 = false;
}
catch(int)
{
printf("exception caught, and about to retry also\n");
continue1 = true;
}
}
return(0);
}

So it turns out to be a recursive throw and handling of the integer
exception. the int 5 is allocated in the stack and therefore i assume
that it is passed to the catch handler by value as a function call...
if that is the case, is it similar to recursive function call and
would cause a stack overflow?

Thanks in advance!!!
The entire try...catch block is completed before the next execution, so the
thrown variable is cleaned up so you won't have that issue.

--
Jim Langston
ta*******@rocketmail.com
Dec 8 '07 #2
On Dec 8, 3:23 pm, Rahul <sam_...@yahoo.co.inwrote:
Hi Everyone,

I have the following code,

int main()
{
bool continue1 = true;
while(continue1)
{
try
{
printf("executed\n");
throw 5;
continue1 = false;
}
catch(int)
{
printf("exception caught, and about to retry also\n");
continue1 = true;
}
}
return(0);

}

So it turns out to be a recursive throw and handling of the integer
exception. the int 5 is allocated in the stack and therefore i assume
that it is passed to the catch handler by value as a function call...
if that is the case, is it similar to recursive function call and
would cause a stack overflow?

Thanks in advance!!!
Does the standard say anything about memory holding the integer 5?
As per the block scope rules, 5 (local variable) would be deallocated
in that block,
if that is the case, how is the value passed to the exception block?
Dec 8 '07 #3
On 2007-12-08 08:01:47 -0500, Rahul <sa*****@yahoo.co.insaid:
>
Does the standard say anything about memory holding the integer 5?
As per the block scope rules, 5 (local variable) would be deallocated
in that block,
if that is the case, how is the value passed to the exception block?
There's a bunch of mechansim behind the curtains. Essentially, the
compiler copies the value to someplace safe.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Dec 8 '07 #4
On Dec 8, 4:34 pm, Pete Becker <p...@versatilecoding.comwrote:
On 2007-12-08 08:01:47 -0500, Rahul <sam_...@yahoo.co.insaid:
Does the standard say anything about memory holding the integer 5?
As per the block scope rules, 5 (local variable) would be deallocated
in that block,
if that is the case, how is the value passed to the exception block?

There's a bunch of mechansim behind the curtains. Essentially, the
compiler copies the value to someplace safe.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
the final object resulting from throw is in catch context and is
destructed by leaving the catch block(after all it is a block).

on a considerable compiler you must not get into trouble with stack
for the above snippet.

regards,
FM.
Dec 8 '07 #5

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

Similar topics

6
by: Boogie El Aceitoso | last post by:
Hi, Is it possible to 'fix'in the catch block whatever caused an exception and return to the offending statement in the try block, and try it again? After raising an exception, I'd like to try...
4
by: Eric Lilja | last post by:
Hello, in my program I have a function (pseudo code): void start_mysql_service() { obtain handle start mysql service using handle if start fails close handle and throw an exception...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
2
by: kpax | last post by:
Hi, While debugging my application when an explicit exception is thrown by me (or an implicit exception is thrown internally) which is not handled anywhere in the stack, the execution breaks as...
3
by: will | last post by:
Hi all. I've got an question about how to catch an exception. In Page_Load, I place a DataGrid, dg1, into edit mode. This will call the method called GenericGridEvent. GenericGridEvent will call...
4
by: Rob Richardson | last post by:
Greetings! I am working on an application that targets a Pocket PC running Windows CE and SQL Server CE. Almost all functions in the application use a Try block with a Catch block that looks...
1
by: metsys | last post by:
We have an ASP.NET 2.0 (C#) application that is divided into multiple layers. The multiple layers come from having a web project and 2 different class library projects in the same solution. I'm...
7
by: Sek | last post by:
Hi Folks! I was pondering over a code and noticed that exception handlers were present in the private, protected as well as public methods. And, ofcourse, public methods were calling priv/prot...
41
by: Zytan | last post by:
Ok something simple like int.Parse(string) can throw these exceptions: ArgumentNullException, FormatException, OverflowException I don't want my program to just crash on an exception, so I must...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.