473,670 Members | 2,228 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

exception throw and handle and resume

Hi Everyone,

I have the following code,

int main()
{
bool continue1 = true;
while(continue1 )
{
try
{
printf("execute d\n");
throw 5;
continue1 = false;
}
catch(int)
{
printf("excepti on 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 1877
Rahul wrote:
Hi Everyone,

I have the following code,

int main()
{
bool continue1 = true;
while(continue1 )
{
try
{
printf("execute d\n");
throw 5;
continue1 = false;
}
catch(int)
{
printf("excepti on 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*******@rocke tmail.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("execute d\n");
throw 5;
continue1 = false;
}
catch(int)
{
printf("excepti on 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...@versatile coding.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
6339
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 to resume the computation after fixing whatever went wrong.
4
1977
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 containing error description
44
4207
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 user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box, etc.). 2. Low-level operations that are used to carry out the high level tasks
2
2351
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 expected but I can not continue. I try start the execution and go back to running mode, but it always comes to the same line where the exception is first thrown.
3
1844
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 a mehtod called ExceptionGenerator that will generate a run-time exception. The exception is caught in GenericGridEvent, but it isn't caught in InitializeComponenet (which doens't suprise me). I can't figure out where to catch an error that may...
4
2033
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 like this: Try TryToDoIt() Catch e as Exception LogTheError(e)
1
1968
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 having difficulties figuring out the best way to handle (catch) exceptions in the different layers and then propagating those errors back up through the call stack to ultimately display something to the end-user. Note this is an intranet...
7
5129
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 methods internally. My thought was, the exception is being rethrown and propagated by the non-public methods to the public methods, causing performance overhead (stack winding etc). I do agree that, the purpose of throwing the exception by...
41
3051
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 handle all of them. I don't care about which one happened, except to write out exception.Message to a log file. It seems verbose to write out three handlers that all do the same thing. So, I could just catch Exception. But, is that...
0
8469
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8661
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5684
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2800
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.