|
-
October 9th, 2002, 09:12 AM
#1
try{ } catch { }
I am having technical difficulties on my PC, so compiling and experimenting is not an option. Therefore I need to ask a question on here.
Question: For the code below. If an exception occurs at line 7 below, then what subsequent lines of code will be executed.
I want to know if (1) The values for First and Second will ever
be set to true? And (2)Will a value be returned at line 18. If so,
will the value be false.
1 bool SomeClass::SomeMethodOfClass(void)
2 {
3 bool First(false);
4 bool Second(false);
5
6 try {
7 char *ForceError=ABC; // An exception occurs here
8 int X=5l
9 Second=true;
10 }
11 catch(...)
12 {
13 // Handle the exception !
14 }
15
16 First=True; // Will First be set to true if an exception occurs.
17
18 return First;
19
20 }
-
October 9th, 2002, 01:30 PM
#2
If an exception is thrown then everything after line #7 would be ignored.
// Second == false
// First == true
Kuphryn
-
October 9th, 2002, 02:37 PM
#3
Actually
First=True;
Will be executed, unless the catch rethrows the exception, or returns.
Jeff
-
October 10th, 2002, 10:00 AM
#4
Jeff is right. But note that this is only true because you used catch with an ellipsis (...) - which catches all exceptions. If you'd defined 'catch' to trap a particular type of exception, it's possible that 'First = TRUE' might never be reached. That would depend upon the actual exception that occurred.
-
October 12th, 2002, 06:26 PM
#5
If exception is there at line 7
Second=true; is not going to execute.
about First = True;
Its really depends upon what r u doing in catch block.
Vinod
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|