CSharp · Console
using System;
public class Program
{
public static void Main()
{
try
{
DoSomethingThatMightFail();
}
catch (Exception ex) when (Log(ex, "An error occurred"))
{
// This catch block will never be reached as Log returns false
}
}
public static void DoSomethingThatMightFail()
{
// This will always throw a DivideByZero exception
var x = 42;
var y = 0;
int z = x / y;
}
static bool Log(Exception ex, string message, params object[] args)
{
Console.WriteLine(message, args);
return false;
}
}