exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 2 question 158 discussion

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

DRAG DROP -
You are developing an application that implements a set of custom exception types. You declare the custom exception types by using the following code segments:

The application includes a function named DoWork that throws .NET Framework exceptions and custom exceptions. The application contains only the following logging methods:

The application must meet the following requirements:
✑ When ContosoValidationException exceptions are caught, log the information by using the static void Log(ContosoValidationException ex) method.
✑ When ContosoDbException or other ContosoException exceptions are caught, log the information by using the static void Log(ContosoException method. ex)
✑ When generic exceptions are caught, log the information by using the static void Log(Exception ex) method.
You need to meet the requirements.
You have the following code:

Which code segments should you include in Target 1, Target 2 and Target 3 to complete the code? (To answer, drag the appropriate code segments to the correct targets in the answer area. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Select and Place:

Show Suggested Answer Hide Answer
Suggested Answer:
Catch the most specific exception first.

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
Asa
Highly Voted 5 years, 10 months ago
1, 2, 3
upvoted 47 times
sscooter1010
5 years, 3 months ago
This is the right answer
upvoted 3 times
...
...
xman
Highly Voted 5 years, 2 months ago
ContosoValidationException ex ContosoDbException ex ContosoException ex
upvoted 6 times
MrSmock
5 years, 2 months ago
This will not catch Generic exception. You will need "Exception ex" to be caught last.
upvoted 3 times
xman
4 years, 11 months ago
Sorry i think you are right it is ContosoValidationException ex ContosoException ex Exception ex 1,2,3
upvoted 5 times
soey
4 years, 9 months ago
No it's not. Question talks only about contoso exceptions there is no word about catching generic exception.
upvoted 2 times
...
...
...
...
demoinq
Most Recent 4 years, 5 months ago
This is the second time I aproached this question with lots of confusion so I decided to code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ExceptionHandling { public class ContosoException : System.Exception { } public class ContosoValidationException : ContosoException { } public class ContosoDBException : ContosoException { } class Program { static void Ble() { throw new Exception(); } static void Main(string[] args) { try { Ble(); }catch(ContosoValidationException ex) { Console.WriteLine("Validation"); }catch(ContosoException ex) { Console.WriteLine("DB or general Contoso"); }catch(Exception ex) { Console.WriteLine("General exception"); } Console.ReadLine(); } } } The answers are: Target 1 = ContosoValidationException Target 2 = ContosoException Target 3 = Exception
upvoted 5 times
...
thiemamd
4 years, 9 months ago
1, 4, 3
upvoted 2 times
thiemamd
4 years, 9 months ago
Am not sure! It would be maybe 123. But can someone explain me why not use 'ContosoDbException' instead of ContosoException
upvoted 1 times
heldercsousa
4 years, 7 months ago
When using ContosoException, ContosoDbException will be catch as well since it implements ContosoException. Same happens to Exception. It catchs all type of exceptions, since all other implements it.
upvoted 1 times
...
Kilsimon
4 years, 7 months ago
"When ContosoDbException or other ContosoException exceptions are caught, log the information by using the static void Log(ContosoException ex) method." If you catch ContosoDbException as the you would log it as ContosoDbException. catch (ContosoDbException ex){ log(ex); }
upvoted 1 times
...
...
...
lh2607
4 years, 10 months ago
ContosoValidationException ex; ContosoException ex; Exception ex;
upvoted 2 times
...
whtvr
5 years, 2 months ago
Asa is correct, the answer is 1,2,3 You need ContosoException, not the ContosoDbException (it inherits the former anyway) and at the end get the generic Exception
upvoted 3 times
thiemamd
4 years, 9 months ago
I don't understand why not use 'ContosoDbException' instead of ContosoException
upvoted 1 times
...
...
LAV
5 years, 6 months ago
Correct answer 1,3,2
upvoted 1 times
mendolf92
5 years, 3 months ago
if the Exception type is at the second place, it will catch ALL the exception types because it is the base type of allexceptions in C#
upvoted 3 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