Sobes.tech
Junior — Senior

Problem when working with exceptions

livecode

Task condition

It is necessary to find out how to rethrow an exception that is generated inside a try block so that it can be handled or propagated further.

public void Test()
{
    try
    {
        var calcResult = Calculate();
        throw new MyCustomException("qwerty");
    }
    
    catch(Exception ex)
    {
        
    }
    
    catch(MyCustomException customEx)
    {
        Console.WriteLine(customEx);
        throw customEx;
    }
}