Exception Handling in C#

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Themes
T
Themes
Community Contributor
Quizzes Created: 3029 | Total Attempts: 1,231,654
| Questions: 30 | Updated: Oct 6, 2026
Please wait...
Question 1 / 31
🏆 Rank #-- ▾
0 %
0/100
Score 0/100

1. In C#, the finally block cannot transfer control using which of the following statements?

Explanation

In C#, the `finally` block is designed to execute cleanup code after a try-catch structure, regardless of whether an exception occurred. Control transfer statements like `break`, `continue`, `return`, or `goto` disrupt the normal flow of execution and are not permitted within a `finally` block. This restriction ensures that the `finally` block completes its execution, allowing for reliable resource management and cleanup, which is essential for maintaining program stability and preventing resource leaks.

Submit
Please wait...
About This Quiz
Exception Handling In C# - Quiz

This assessment focuses on exception handling in C#, evaluating your understanding of key concepts such as exception types, keywords, and error management strategies. It's essential for developers to grasp these principles to write robust and error-resistant code, making this knowledge highly relevant for anyone looking to enhance their C# programming... see moreskills. see less

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. Match each exception type with its correct description.

Submit

3. The _____ keyword is used to manually throw an exception in C#.

Submit

4. To create a custom exception, the class must inherit from System._____ class.

Submit

5. The exception System._____ is thrown when errors occur in arithmetic or conversion operations.

Submit

6. In C#, the _____ keyword catches the exception that is thrown in a try block.

Submit

7. The throw keyword can only be used inside a try-catch block.

Submit

8. A custom exception class in C# does not need to inherit from the Exception class.

Submit

9. The finally block will execute even if no exception is thrown.

Submit

10. ApplicationException is generated by the Common Language Runtime (CLR).

Submit

11. The try keyword is used to check for the occurrence of any exceptions enclosed to it.

Submit

12. What is the purpose of the try keyword in exception handling?

Explanation

The try keyword is used in exception handling to define a block of code that will be monitored for exceptions. When code within the try block executes, if an exception occurs, it can be caught and handled appropriately, preventing the program from crashing. This allows developers to manage errors gracefully and implement recovery mechanisms, ensuring that the program continues to run smoothly or fails gracefully. Overall, the try block serves as a safeguard for potentially error-prone code.

Submit

13. Which exception is thrown when an invalid argument is passed to a method?

Explanation

When a method receives an argument that is not valid or does not meet the method's requirements, it throws a System.ArgumentException. This exception indicates that the argument provided to the method is inappropriate, such as being out of the expected range or of the wrong type. It serves as a way to enforce input validation and helps developers identify issues with the arguments being passed to methods, ensuring that the program can handle errors gracefully.

Submit

14. In Listing 2, how many catch blocks are used?

Explanation

In Listing 2, there are two catch blocks present, which are used to handle exceptions that may arise during the execution of the associated try block. Each catch block is designed to catch specific types of exceptions, allowing for tailored error handling. This structure helps in maintaining robust code by ensuring that different error scenarios can be addressed appropriately, thus improving the overall reliability of the program.

Submit

15. Which two types of exceptions exist in C#?

Explanation

In C#, exceptions are categorized to help developers manage errors effectively. ApplicationException is a base class for exceptions defined by applications, allowing for custom error handling specific to application logic. SystemException, on the other hand, is a base class for exceptions that occur during the execution of the runtime, such as null reference or index out of range errors. Together, these two types provide a structured way to handle both application-specific and system-level errors, making debugging and error management more systematic.

Submit

16. What is the base class for all exceptions in C#?

Explanation

In C#, the base class for all exceptions is the `Exception` class. This class serves as the foundation for all exception types, providing essential properties and methods for error handling. Derived classes, such as `SystemException` and `ApplicationException`, extend its functionality to represent specific error conditions. By using `Exception` as the base, C# ensures a consistent approach to managing errors, allowing developers to catch and handle exceptions in a uniform manner across different parts of an application.

Submit

17. To create a custom exception class in C#, it must inherit from which class?

Explanation

In C#, custom exception classes are designed to provide specific error handling capabilities. To ensure they integrate seamlessly with the .NET exception handling framework, these classes must inherit from `System.Exception` or one of its derived classes. This inheritance allows the custom exceptions to utilize built-in functionalities, such as stack trace generation and serialization, while also ensuring that they can be caught and handled within the standard try-catch constructs of the language.

Submit

18. What happens when a throw keyword is used outside of a try-catch block?

Explanation

When a throw keyword is used outside of a try-catch block, the program does not have a mechanism to handle the thrown exception. Consequently, the runtime environment detects the unhandled exception, which leads to the termination of the application. This results in an error message being displayed to the user, indicating that an unexpected issue has occurred, and the application closes to prevent further complications. This behavior emphasizes the importance of proper exception handling in programming to maintain application stability.

Submit

19. Which exception is thrown when an unacceptable null argument is passed to a method?

Explanation

System.ArgumentNullException is specifically designed to handle cases where a method receives a null argument that is not permitted. This exception indicates that a method argument that is expected to be non-null is actually null, helping developers identify issues related to incorrect method usage. Unlike System.ArgumentException, which covers a broader range of argument-related errors, System.ArgumentNullException focuses solely on null values, making it the most appropriate choice for this scenario.

Submit

20. How many keywords are used for handling exceptions in C#?

Explanation

In C#, four keywords are specifically used for exception handling: `try`, `catch`, `finally`, and `throw`. The `try` block is used to wrap code that may cause an exception, while the `catch` block handles the exception when it occurs. The `finally` block, if present, executes code regardless of whether an exception was thrown, ensuring that cleanup actions are performed. The `throw` keyword is used to raise an exception manually. Together, these keywords provide a robust structure for managing errors in C# applications.

Submit

21. Which exception checks if the format of a string or argument is invalid?

Explanation

System.FormatException is thrown when the format of an argument, typically a string, does not conform to the expected format. This can occur when trying to convert a string to a different data type, such as an integer or date, and the string does not match the required format. It specifically addresses issues related to formatting, distinguishing it from other exceptions like ArgumentException, which deals with general argument issues, or ArgumentNullException, which is concerned with null arguments.

Submit

22. Which exception is thrown when the execution stack is exhausted due to too many pending method calls?

Explanation

A System.StackOverflowException occurs when a program's call stack exceeds its limit due to excessive method calls, often from deep or infinite recursion. Each method call consumes stack space, and when this space is exhausted, the exception is thrown to indicate that the execution cannot continue. This type of exception specifically signals that the stack has overflowed, distinguishing it from other exceptions that relate to memory or indexing issues.

Submit

23. Which exception is thrown when available memory is insufficient for a memory allocation request?

Explanation

System.OutOfMemoryException is thrown when the system cannot allocate memory for an object due to insufficient available memory. This typically occurs when the application requests more memory than is available, either because the system is low on memory or because the memory limit for the application itself has been reached. Unlike other exceptions, such as System.StackOverflowException, which occurs due to excessive stack usage, OutOfMemoryException specifically relates to heap memory allocation failures.

Submit

24. What is the correct syntax for manually throwing an exception in C#?

Explanation

In C#, to manually throw an exception, you need to create an instance of an exception class and then use the `throw` keyword. The syntax `throw new exception_object;` correctly combines the `throw` statement with the instantiation of the exception object, ensuring that the exception is raised. The other options either misuse the `throw` keyword or fail to create a new instance of the exception, making them invalid. This syntax is essential for error handling in C# applications.

Submit

25. Which keyword in C# executes a block of code regardless of whether an exception is thrown or not?

Explanation

The `finally` keyword in C# is used to define a block of code that will always execute after a `try` block, regardless of whether an exception was thrown or caught. This ensures that critical cleanup actions, such as closing file handles or releasing resources, are performed. The `finally` block is particularly useful for maintaining program stability and resource management, as it guarantees execution even if an error occurs in the `try` or `catch` blocks.

Submit

26. Which keyword is used to manually throw an exception in C#?

Explanation

In C#, the keyword "throw" is used to manually raise an exception. This allows developers to create custom error-handling scenarios by signaling that an exceptional condition has occurred. When "throw" is used, it can also pass an instance of an exception class, providing detailed information about the error. This is essential for robust error management, enabling the program to handle issues gracefully and maintain control flow.

Submit

27. Which exception is thrown when an array is accessed with an index less than zero or greater than its maximum length?

Explanation

Accessing an array with an index that is either negative or exceeds the maximum allowable index results in an out-of-bounds error. In .NET, this situation specifically triggers a System.IndexOutOfRangeException. This exception indicates that the index used to access the array is invalid, ensuring that developers are alerted to potential errors in their code related to improper array indexing.

Submit

28. Which exception is thrown when an overflow occurs in a checked operation?

Explanation

An overflow occurs when a calculation exceeds the storage capacity of the data type used. In .NET, the `System.OverflowException` is specifically designed to handle cases where an arithmetic operation results in a value that is too large or too small for the designated type. This exception is thrown during checked operations, which are explicitly set to monitor arithmetic overflows. This helps developers identify and manage potential errors in their code, ensuring that they can handle unexpected situations gracefully.

Submit

29. Which type of exception is generated by the Common Language Runtime (CLR)?

Explanation

SystemException is generated by the Common Language Runtime (CLR) to indicate errors that occur during the execution of a program that are related to the system, such as runtime errors. These exceptions are predefined and represent common issues that can arise, such as out-of-memory errors or invalid operations. They serve as a way for the CLR to communicate serious problems that need to be addressed, allowing developers to handle such exceptions appropriately within their applications.

Submit

30. Which namespace contains the Exception class in C#?

Explanation

In C#, the Exception class is defined within the System namespace, which serves as the root namespace for fundamental classes in the .NET Framework. This namespace includes essential types and functions, including error handling classes like Exception and its derived types. Other namespaces, such as System.IO or System.Collections, focus on specific functionalities, but for general exception handling, the System namespace is where the Exception class resides, making it the correct choice.

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (30)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
In C#, the finally block cannot transfer control using which of the...
Match each exception type with its correct description.
The _____ keyword is used to manually throw an exception in C#.
To create a custom exception, the class must inherit from System._____...
The exception System._____ is thrown when errors occur in arithmetic...
In C#, the _____ keyword catches the exception that is thrown in a try...
The throw keyword can only be used inside a try-catch block.
A custom exception class in C# does not need to inherit from the...
The finally block will execute even if no exception is thrown.
ApplicationException is generated by the Common Language Runtime...
The try keyword is used to check for the occurrence of any exceptions...
What is the purpose of the try keyword in exception handling?
Which exception is thrown when an invalid argument is passed to a...
In Listing 2, how many catch blocks are used?
Which two types of exceptions exist in C#?
What is the base class for all exceptions in C#?
To create a custom exception class in C#, it must inherit from which...
What happens when a throw keyword is used outside of a try-catch...
Which exception is thrown when an unacceptable null argument is passed...
How many keywords are used for handling exceptions in C#?
Which exception checks if the format of a string or argument is...
Which exception is thrown when the execution stack is exhausted due to...
Which exception is thrown when available memory is insufficient for a...
What is the correct syntax for manually throwing an exception in C#?
Which keyword in C# executes a block of code regardless of whether an...
Which keyword is used to manually throw an exception in C#?
Which exception is thrown when an array is accessed with an index less...
Which exception is thrown when an overflow occurs in a checked...
Which type of exception is generated by the Common Language Runtime...
Which namespace contains the Exception class in C#?
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!