98-372 · Question #57
Allen is creating an application using .NET Framework 4.0. What structure will he use to handle exceptions in the application?
The correct answer is C. Try-catch. The try...catch block is used to handle runtime errors. In an event procedure, the try statement is placed just before the statements that might cause an error. The catch statement is placed just before the list of statements that are to be run if a runtime error occurs. //Statem
Question
Allen is creating an application using .NET Framework 4.0. What structure will he use to handle exceptions in the application?
Options
- ACatch-exception
- BCatch-finally
- CTry-catch
- DThrow-catch
How the community answered
(29 responses)- A10% (3)
- B7% (2)
- C79% (23)
- D3% (1)
Explanation
The try...catch block is used to handle runtime errors. In an event procedure, the try statement is placed just before the statements that might cause an error. The catch statement is placed just before the list of statements that are to be run if a runtime error occurs. //Statements that might cause a runtime error. //Statements to be run if a runtime error occurs. Answer: D is incorrect. The throw statement creates an exception within a procedure and explicitly throws the exception. The occurrence of the statement within a code enforces the program to use a pre-existing exception handling code, even if no runtime error has occurred. This statement is generally used with either a try-catch statement or a try-finally statement. It can also be used to rethrow the caught exception. Answer: A is incorrect. Exception is an object that is generated at runtime. It describes a problem encountered during the execution of a program. Answer: B is incorrect. A block of code that appears just after the finally statement is called a finally block. The statements in a finally block are executed immediately after execution of the try/catch block. The finally block is optional. However, each try statement must have at least one catch block or a finally block. When a finally block is defined in a source code, it is guaranteed to execute, regardless of whether or not an exception is thrown.
Topics
Community Discussion
No community discussion yet for this question.