
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Exception Propagation in C#
Exception Propogation can be understood by how exception handling works in C#.
In try, when an exception occurs the corresponding catch blocks are checked. This is done to see if they can catch the exception. If no matching exception is found, the exception is propagated to a higher-level try block. This repeats until the exception is caught. In case, the exception isn’t caught, the execution of the program comes to an end.
The above concept is explain in the below example showing nested try statements.
Example
using System; using System.Text; public class Demo { public static void Main() { try { try { throw new ArgumentException(); }catch (NullReferenceException e) { Console.WriteLine("catch one"); } finally { Console.WriteLine("finally one"); } } catch (Exception e) { Console.WriteLine("catch two"); } finally { Console.WriteLine("finally two"); } Console.ReadLine(); } }
Output
finally one catch two finally two
- Related Articles
- Exception propagation in Java
- Exception propagation in Java programming
- What is exception propagation in Java?
- Exception in C#
- Null Pointer Exception in C#
- Understanding IndexOutOfRangeException Exception in C#
- Exception Handling Basics in C++
- What is exception handling in C#?
- User-defined Custom Exception in C#
- Exception Handling in C++ vs Java
- Exception handling and object destruction in C++
- C# Exception Handling Best Practices
- Space Wave Propagation
- How to capture null reference exception in C#?
- Comparison of Exception Handling in C++ and Java

Advertisements