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

try catch

MrPickle
100 100+
With try catch blocks what happens when multiple exceptions are thrown?

Is there chance for multiple exceptions or does it stop as soon as one is thrown?

eg;

Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3.     foo(); //throws an exception
  4.     bar(); //Will this function be executed? If so what happens if it throws an exception?
  5. }
  6. catch(...)
  7. {
  8.    //...
  9. }
May 13 '09 #1
2 1711
Banfa
9,065 Expert Mod 8TB
If foo throws an exception that is catchable by the catch block the execution switches to the catch block, bar is never executed.

If foo throws an exception that is not catchable by the catch block then stack-unwinding happens. That is the exception is passed up through the current call stack until either a catch block for the exception is found or main is exited at which point the program terminates with the exception, again bar is never executed.
May 13 '09 #2
RRick
463 Expert 256MB
In a single process (I think) only one exception can be thrown at a time. The reason for this is because of the code execution described above by Banfa. No other exception can be created because the only code being executed is the code for the original exception.

That sounds reasonable, but what happens in a threaded environment? Since any number of threads can be running concurrently, any number of exceptions could be thrown. But the same logic for having a single exception per process also applies to threads. Each thread processes a single exception at a time and when the exception goes beyond the scope of the thread, the thread is terminated. I don't believe that will cause the entire program to be stopped.
May 15 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: kaeli | last post by:
Hey all, I'd like to start using the try/catch construct in some scripts. Older browsers don't support this. What's the best way to test for support for this construct so it doesn't kill...
11
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.