Dive into these 30 carefully crafted multiple-choice questions on VB.NET error handling, covering exceptions, Try…Catch…Finally, throwing exceptions, and debugging. Perfect for learning and exam preparation!
Error Handling MCQs
1. Introduction to Errors and Exceptions
What is an exception in VB.NET? a) A syntax error b) A runtime error c) A logical error d) A compilation warning
Which of the following is a built-in exception class in VB.NET? a) System.Exception b) VB.NET.Error c) Error.Exception d) System.Runtime
What happens when an unhandled exception occurs in VB.NET? a) Program continues execution b) Program crashes c) Program logs the exception and continues d) Program restarts
Which keyword is used to raise an exception in VB.NET? a) Catch b) Throw c) Raise d) Exception
Exceptions in VB.NET are part of which namespace? a) System.Runtime.Error b) System.ExceptionHandling c) System d) System.Diagnostics
2. Try…Catch…Finally
What is the primary purpose of the Try block in VB.NET? a) To log errors b) To execute code that might throw an exception c) To catch errors d) To handle finally operations
What does the Finally block do in VB.NET error handling? a) Catches exceptions b) Executes only if an exception is thrown c) Executes regardless of whether an exception occurs or not d) Logs the exception details
In a Try…Catch block, where do you place code that must execute even if an exception occurs? a) In the Catch block b) In the Finally block c) After the Try…Catch block d) Before the Try block
Which of the following is true about the Catch block? a) Only one Catch block is allowed b) Multiple Catch blocks can handle specific exceptions c) Catch blocks must always include Finally d) Catch blocks execute before the Try block
What happens if no exception occurs in the Try block? a) The Catch block executes b) The Finally block is skipped c) Both Catch and Finally blocks are skipped d) The Finally block executes
3. Throwing Exceptions
Which method is used to throw a custom exception? a) Catch b) Raise c) Throw d) Try
What type of exceptions can be thrown in VB.NET? a) Only system-defined exceptions b) Only user-defined exceptions c) Both system-defined and user-defined exceptions d) None
When throwing an exception, what must you provide? a) The error code b) A custom exception handler c) An instance of an exception class d) An error log
How do you throw an exception in VB.NET? a) Throw exceptionName() b) Throw New exceptionClass() c) Raise exceptionName() d) Catch New exceptionName()
What is the best practice when throwing exceptions in VB.NET? a) Avoid adding a custom message b) Only use built-in exceptions c) Use meaningful messages to describe the error d) Throw exceptions without context
4. Debugging Basics
What does the Debugging process involve? a) Writing code b) Fixing logical and runtime errors c) Managing databases d) Deploying applications
What is the purpose of breakpoints in VB.NET? a) To stop the program permanently b) To pause execution for inspection c) To fix errors automatically d) To optimize performance
Which window in Visual Studio shows variable values during debugging? a) Call Stack b) Locals c) Immediate d) Watch
How can you start debugging in Visual Studio? a) Press F5 b) Press Ctrl+D c) Click “Start Debug” in Tools menu d) Press Alt+F5
What is the difference between Debug.WriteLine and Console.WriteLine? a) Debug.WriteLine outputs only in debug mode b) Console.WriteLine outputs only in debug mode c) Both output to the console d) Both are identical
Additional Scenarios
What type of exceptions can the Catch block handle? a) Only syntax errors b) Both system-defined and user-defined exceptions c) Only runtime errors d) Only compilation errors
What happens if no matching Catch block is found for an exception? a) Exception is ignored b) Program continues execution c) Program crashes d) Exception is passed to the Finally block
How do you catch all exceptions in VB.NET? a) Use Catch Without Arguments b) Use Catch ex As Exception c) Use Catch All d) Use Finally
Which Visual Studio tool helps in diagnosing runtime exceptions? a) Error List b) Immediate Window c) Call Stack d) Breakpoints
When should you log exceptions in a real-world application? a) Only during debugging b) Always log exceptions for monitoring and debugging c) Never log exceptions d) Only when the program crashes
Debugging Essentials
Which tool allows real-time monitoring of variable changes during debugging? a) Locals b) Watch c) Call Stack d) Output
What is the “Step Over” feature in debugging? a) Runs the program until the next breakpoint b) Executes a function without stepping into it c) Executes the entire program d) Stops execution
How can you stop debugging in Visual Studio? a) Click “Stop Debugging” in the Debug menu b) Press F12 c) Press Shift+D d) Click “Close”
What is a runtime error? a) An error in program design b) An error that occurs during program execution c) A syntax error d) A compilation error
What tool can be used to view detailed logs of exceptions in Visual Studio? a) Error List b) Output Window c) Locals Window d) Exception Helper
Answer Table
Qno
Answer (Option with Text)
1
b) A runtime error
2
a) System.Exception
3
b) Program crashes
4
b) Throw
5
c) System
6
b) To execute code that might throw an exception
7
c) Executes regardless of whether an exception occurs or not
8
b) In the Finally block
9
b) Multiple Catch blocks can handle specific exceptions
10
d) The Finally block executes
11
c) Throw
12
c) Both system-defined and user-defined exceptions
13
c) An instance of an exception class
14
b) Throw New exceptionClass()
15
c) Use meaningful messages to describe the error
16
b) Fixing logical and runtime errors
17
b) To pause execution for inspection
18
b) Locals
19
a) Press F5
20
a) Debug.WriteLine outputs only in debug mode
21
b) Both system-defined and user-defined exceptions
22
c) Program crashes
23
b) Use Catch ex As Exception
24
c) Call Stack
25
b) Always log exceptions for monitoring and debugging