How to Rethrow an Exception in C# ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

There are times when you want to handle the exception and then pass it to the higher level . Below is a sample code snippet demonstrating how to Rethrow an exception in C# .

How to Rethrow an Exception in C# ?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace AbundantcodeConsole
{ 
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                int input = 10;
                int val = 0;
                int Output = input / val;
            }
            catch(DivideByZeroException ex)
            {
                throw;
            }          
        }

    }  
}
%d bloggers like this: