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.

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

  1. Paul says:

    C:
    The code doesn’t match the question….
    I think the code as shown is the solution-code. The question-code should be:
    catch (Exception e) {}
    catch (ArgumentNullException e) {}

    Ordering of exceptions is a recurring theme for the c# exam.




    13



    0

Leave a Reply