exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 2 question 61 discussion

Actual exam question from Microsoft's 70-483
Question #: 61
Topic #: 2
[All 70-483 Questions]

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?

  • 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.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
banshee
Highly Voted 5 years ago
The code in question is wrong. The code can have this syntax error message only when order of catch blocks is: catch(Exception e) and then catch(ArgumentNullException e). And in that case, correct answer is C (Catch the ArgumentNullException exception first).
upvoted 20 times
...
andresdatacom
Highly Voted 5 years ago
Yo creo que la pregunta esta al contrario y es como el codigo de abajo, asumiendo esto la respuesta es la A public void metodh() { try { } catch (Exception e) { throw e; } catch (ArgumentNullException e) { throw e; } }
upvoted 10 times
RaggedHagrid
4 years ago
Si, pregunta es malo.
upvoted 1 times
...
...
KT1978
Most Recent 4 years, 3 months ago
I think this should be Answer C and in the snippet the 2 catch blocks are the wrong way around
upvoted 2 times
noussa
3 years, 10 months ago
Indeed They gave us the solution instead of the problem :D The answer is C and the code snippet is wrong based on the exception the code is returning
upvoted 1 times
...
...
lh2607
4 years, 5 months ago
catch(Exception e) should be the first catch block in this code for this question to be right. Then C would be the correct answer as catch(Exception e) should always be last when using multiple exception types since it is the least specific.
upvoted 1 times
...
Shema
4 years, 10 months ago
So yeah, Code is OK. And 'A' can't be true bcz ArgumentNullException inherited from ArgumentException
upvoted 2 times
...
AntChekalin
5 years, 1 month ago
Just try this code. Everything works fine without any changes.
upvoted 7 times
...
supersunny
5 years, 4 months ago
A. is the answer. Catch the ArgumentException instead of the ArgumentNullException
upvoted 2 times
...
Nyxius
5 years, 7 months ago
Question is wrong, you're probably lacking another exception catch phrase
upvoted 9 times
thiemamd
4 years, 4 months ago
I agree with you. I compiled the code but the behaviour is different than described. For the question to be correct they should reverse the order between the two exceptions
upvoted 3 times
noussa
3 years, 11 months ago
True; Exception needs to be the first catch for this to give the described exception. This is the proof: https://dotnetfiddle.net/
upvoted 2 times
noussa
3 years, 11 months ago
Sorry wrong link: https://dotnetfiddle.net/5zdHsl
upvoted 1 times
...
...
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago