MCQs on Error Handling | Visual Basic .NET (VB.NET)

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

  1. What is an exception in VB.NET?
    a) A syntax error
    b) A runtime error
    c) A logical error
    d) A compilation warning
  2. 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
  3. 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
  4. Which keyword is used to raise an exception in VB.NET?
    a) Catch
    b) Throw
    c) Raise
    d) Exception
  5. 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

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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

  1. Which method is used to throw a custom exception?
    a) Catch
    b) Raise
    c) Throw
    d) Try
  2. 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
  3. 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
  4. How do you throw an exception in VB.NET?
    a) Throw exceptionName()
    b) Throw New exceptionClass()
    c) Raise exceptionName()
    d) Catch New exceptionName()
  5. 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

  1. What does the Debugging process involve?
    a) Writing code
    b) Fixing logical and runtime errors
    c) Managing databases
    d) Deploying applications
  2. 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
  3. Which window in Visual Studio shows variable values during debugging?
    a) Call Stack
    b) Locals
    c) Immediate
    d) Watch
  4. 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
  5. 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

  1. 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
  2. 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
  3. 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
  4. Which Visual Studio tool helps in diagnosing runtime exceptions?
    a) Error List
    b) Immediate Window
    c) Call Stack
    d) Breakpoints
  5. 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

  1. Which tool allows real-time monitoring of variable changes during debugging?
    a) Locals
    b) Watch
    c) Call Stack
    d) Output
  2. 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
  3. 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”
  4. 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
  5. 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

QnoAnswer (Option with Text)
1b) A runtime error
2a) System.Exception
3b) Program crashes
4b) Throw
5c) System
6b) To execute code that might throw an exception
7c) Executes regardless of whether an exception occurs or not
8b) In the Finally block
9b) Multiple Catch blocks can handle specific exceptions
10d) The Finally block executes
11c) Throw
12c) Both system-defined and user-defined exceptions
13c) An instance of an exception class
14b) Throw New exceptionClass()
15c) Use meaningful messages to describe the error
16b) Fixing logical and runtime errors
17b) To pause execution for inspection
18b) Locals
19a) Press F5
20a) Debug.WriteLine outputs only in debug mode
21b) Both system-defined and user-defined exceptions
22c) Program crashes
23b) Use Catch ex As Exception
24c) Call Stack
25b) Always log exceptions for monitoring and debugging
26b) Watch
27b) Executes a function without stepping into it
28a) Click “Stop Debugging” in the Debug menu
29b) An error that occurs during program execution
30d) Exception Helper

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top