.NET Fiddle

CSharp · Console

/Program.cs

using System;

// see: https://stackoverflow.com/documentation/c%23/40/exception-handling/169/using-the-exception-object#t=201706260855258771454
public class Program
{


	void DoSomething() 
	{
		int b=1; int c=5;
		try
		{
			var a = 1; 
			b = a - 1;
			c = a / b;
			a = a / c;
		}        
		catch (DivideByZeroException dEx) when (b==0)
		{
			// we're throwing the same kind of exception
			throw new DivideByZeroException("Cannot divide by b because it is zero", dEx);
		}
		catch (DivideByZeroException dEx) when (c==0)
		{
			// we're throwing the same kind of exception
			throw new DivideByZeroException("Cannot divide by c because it is zero", dEx);
		}
	}
	
	public void Main()
	{    
		try
		{
			DoSomething();
		}
		catch (Exception ex)
		{
			// Logs full error information (incl. inner exception)
			Console.Write(ex.ToString()); 
		}    
	}
}

;