Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computer Certification > MCAD > Try Catch question

Reply
Thread Tools

Try Catch question

 
 
Ehab Zaky
Guest
Posts: n/a
 
      05-01-2004
Dear all,
While studying in some study guide for 316, I found a question that asks for
the output of the following code.

try {
Debug.WriteLine(“Inside Try”);
throw(new IOException());}
catch (IOException e) {
Debug.WriteLine (“IOException Caught”);}
catch (Exception e) {
Debug.WriteLine(“Exception Caught”);}
finally {
Debug.WriteLine (“Inside Finally”);}
Debug.WriteLine (“After End Try”);

- I tried this code and the output as I expected was

Inside Try
IOException Caught
Inside Finally
After End Try

- But the answer in the study guide was
Inside Try
IOException Caught
Inside Finally

Am I right? or what?

Thanks in advance
Yours,
Ehab Zaky


 
Reply With Quote
 
 
 
 
Yorkie
Guest
Posts: n/a
 
      05-01-2004
You are right!


>-----Original Message-----
>Dear all,
>While studying in some study guide for 316, I found a

question that asks for
>the output of the following code.
>
>try {
> Debug.WriteLine("Inside Try");
> throw(new IOException());}
>catch (IOException e) {
> Debug.WriteLine ("IOException Caught");}
>catch (Exception e) {
> Debug.WriteLine("Exception Caught");}
>finally {
> Debug.WriteLine ("Inside Finally");}
>Debug.WriteLine ("After End Try");
>
>- I tried this code and the output as I expected was
>
>Inside Try
>IOException Caught
>Inside Finally
>After End Try
>
>- But the answer in the study guide was
>Inside Try
>IOException Caught
>Inside Finally
>
>Am I right? or what?
>
>Thanks in advance
>Yours,
>Ehab Zaky
>
>
>.
>

 
Reply With Quote
 
 
 
 
Udrea Emil
Guest
Posts: n/a
 
      05-02-2004
You are wrong. Due to the fact that the line code: "throw(new IOException())" exists, all that follows after "..finally block.." won't be done. If you commented this line code, your solution would be correct

Sincerly
Emil Udrea
 
Reply With Quote
 
Yorkie
Guest
Posts: n/a
 
      05-03-2004
But wouldn't the Catch clause handle the exception and
stop it from bubbling up through the stack ?

Therefore, the processing would continue after
the 'try..catch..finally' block as the exception has been
caught and handled, which would mean the 'Debug.WriteLine
("After End Try");' statement would be executed.



>-----Original Message-----
>You are wrong. Due to the fact that the line code: "throw

(new IOException())" exists, all that follows
after "..finally block.." won't be done. If you commented
this line code, your solution would be correct.
>
>Sincerly,
> Emil Udrea
>.
>

 
Reply With Quote
 
M.
Guest
Posts: n/a
 
      05-04-2004
Yes, you're right.

This is the correct answer:

Inside Try
IOException Caught
Inside Finally
After End Try

Regards,
M, MCP (70-316)

>-----Original Message-----
>Dear all,
>While studying in some study guide for 316, I found a

question that asks for
>the output of the following code.
>
>try {
> Debug.WriteLine("Inside Try");
> throw(new IOException());}
>catch (IOException e) {
> Debug.WriteLine ("IOException Caught");}
>catch (Exception e) {
> Debug.WriteLine("Exception Caught");}
>finally {
> Debug.WriteLine ("Inside Finally");}
>Debug.WriteLine ("After End Try");
>
>- I tried this code and the output as I expected was
>
>Inside Try
>IOException Caught
>Inside Finally
>After End Try
>
>- But the answer in the study guide was
>Inside Try
>IOException Caught
>Inside Finally
>
>Am I right? or what?
>
>Thanks in advance
>Yours,
>Ehab Zaky
>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I have a second TRY inside the first TRY/CATCH in ASP.NET ??? bienwell ASP .Net 4 05-27-2005 05:05 PM
Try, Try, Try, again... Rick12N4@netscape.net Computer Support 3 01-29-2005 04:02 PM
Try Catch Exception Question Matt Java 5 06-28-2004 04:35 AM
try-catch & throw Exception Question Matt Java 1 06-12-2004 10:33 AM
Question: Try,Catch,Finally VB Programmer ASP .Net 1 08-07-2003 07:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57