PrepAway - Latest Free Exam Questions & Answers

You need to ensure that the code can be compiled

You are developing an application.
The application contains the following code:

When you compile the code, you receive the following syntax error message: “A previous
catch clause already catches all exceptions of this or a super type (‘System.Exception’).”
You need to ensure that the code can be compiled. What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Catch the ArgumentException exception instead of the ArgumentNullException exception.

B.
Throw a new exception in the second catch block.

C.
Catch the ArgumentNullException exception first.

D.
Re-throw the exception caught by the second catch block.

11 Comments on “You need to ensure that the code can be compiled

  1. My'nD says:

    The code source can’t be correct, no error would be shown. This would only be the case if the two catch block were in reverse order.
    Let’s say it is, answer A would nevertheless not change anything (when exception is caught, argumentexception is caught too, moreover, there isn’t an argumentexception thrown but an argumentnullexception.
    Correct answer would be C as I say upper, this would make the code as we have here, which is good.




    1



    0
  2. Saikat says:

    Dear poster, please do not post wrong question. This kind of question kills the time of the reader’s to find ‘what’s wrong with the code’. absolute time killing activity




    5



    0
  3. Marina says:

    the code is:
    try
    {
    string orderRefNumber = null;
    ProccessOrders(orderRefNumber);
    }
    catch (Exception e)
    {
    Console.WriteLine(“{0} exception caught”, e);
    }
    catch (ArgumentNullException e)
    {
    Console.WriteLine(“{0} exception caught”, e);
    }

    So answer is: C




    4



    0
  4. f9p says:

    The right code is:
    static void Main()
    {
    try
    {
    string orderRefNumber = null;
    ProcessOrders(orderRefNumber);
    }
    catch (Exception e)
    {
    Console.WriteLine(e.Message);
    }
    catch (ArgumentNullException e){
    Console.WriteLine(e.Message);
    }
    }

    And the answer is C.




    0



    1

Leave a Reply