These days, most languages have some variation on the “structured exception handling” concept. Exceptions get thrown inside of a “try” block, and then a search begins for a matching “catch” block, specific to that kind of exception. Each type of exception can be handled differently, which allows minor errors to print messages for the user, while fatal, state-corrupting errors can lead to the application exiting and hopefully not damaging any data.
A good developer catches all of the possible exceptions. By that standard, the contractor who gave Martina this code must be one of the best :
#region Catch clauses
catch (AmbiguousMatchException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (TargetException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (WaitHandleCannotBeOpenedException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (AbandonedMutexException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (TypeLoadException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (IndexOutOfRangeException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (KeyNotFoundException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (InvalidCastException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (MemberAccessException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (SecurityException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (SharpZipBaseException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (ArgumentException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (OverflowException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (System.Configuration.ConfigurationException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (ExecutionEngineException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (FormatException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (InvalidOperationException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (OutOfMemoryException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (NotSupportedException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (NullReferenceException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (OperationCanceledException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (RankException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (TransactionException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (UnauthorizedAccessException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (XmlException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (IOException ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
catch (Exception ex)
{
OnErrorOccurred(new ErrorOccurredEventArgs("An error occured during backup process.", ex));
}
finally
{
CleanUpCancelledBackup();
}