Try Catch question

Discussion in 'MCAD' started by Ehab Zaky, May 1, 2004.

  1. Ehab Zaky

    Ehab Zaky Guest

    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
    Ehab Zaky, May 1, 2004
    #1
    1. Advertising

  2. Ehab Zaky

    Yorkie Guest

    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
    >
    >
    >.
    >
    Yorkie, May 1, 2004
    #2
    1. Advertising

  3. Ehab Zaky

    Udrea Emil Guest

    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
    Udrea Emil, May 2, 2004
    #3
  4. Ehab Zaky

    Yorkie Guest

    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
    >.
    >
    Yorkie, May 3, 2004
    #4
  5. Ehab Zaky

    M. Guest

    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
    >
    >
    >.
    >
    M., May 4, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sarah Stewart
    Replies:
    1
    Views:
    642
    =?Utf-8?B?QnJhaW5Mb2Nr?=
    May 11, 2005
  2. Dmitriy Lapshin [C# / .NET MVP]

    Variables in catch(...) clauses?

    Dmitriy Lapshin [C# / .NET MVP], Feb 26, 2004, in forum: MCSD
    Replies:
    9
    Views:
    537
    The Poster Formerly Known as Kline Sphere
    Mar 2, 2004
  3. =?Utf-8?B?UGFwcmkgQ2hha3Jhdm9ydHk=?=

    Error by Catch

    =?Utf-8?B?UGFwcmkgQ2hha3Jhdm9ydHk=?=, May 20, 2004, in forum: MCSD
    Replies:
    1
    Views:
    468
    The Poster Formerly Known as Kline Sphere
    May 20, 2004
  4. Try, Try, Try, again...

    , Jan 29, 2005, in forum: Computer Support
    Replies:
    3
    Views:
    615
  5. Gurumurthy_G
    Replies:
    0
    Views:
    419
    Gurumurthy_G
    Jul 9, 2013
Loading...

Share This Page