PrepAway - Latest Free Exam Questions & Answers

How should you write the catch block?

DRAG DROP
You are creating a method that saves information to a database.
You have a static class named LogHelper. LogHelper has a method named Log to log the exception.
You need to use the LogHelper Log method to log the exception raised by the database server. The
solution must ensure that the exception can be caught by the calling method, while preserving the
original stack trace.

How should you write the catch block? (Develop the solution by selecting and ordering the required
code snippets. You may not need all of the code snippets.)

PrepAway - Latest Free Exam Questions & Answers

Answer: See the explanation

Explanation:
Box 1:

Box 2:

Box 3: throw;
Box 4:

Note:
Catch the database exception, log it, and then rethrow it.
* SQLException
An exception that provides information on a database access error or other errors.

3 Comments on “How should you write the catch block?


Leave a Reply