Jeżeli istnieje potrzeba przechwycenia błędów systemowych (CSE, corrupted state exceptions) w ramach naszej aplikacji, należy oznaczyć funkcję atrybutem HandleProcessCorruptedStateExceptions z przestrzeni System.Runtime.ExceptionServices.
[HandleProcessCorruptedStateExceptions]
static int Main(string[] args)
{
try
{
// Some execution
return 0;
}
catch (Exception ex)
{
// Catch all CSE (Corrupted State Exception)
Console.WriteLine(ex.ToString());
// Inform OS that critical error occured
return -1;
}
}