Gotta Catch 'Em All
by Remy Porter
in CodeSOD
on 2024-04-03
It's good to handle any exception that could be raised in some useful way. Frequently, this means that you need to take advantage of the catch block's ability to filter by type so you can do something different in each case. Or you could do what Adam's co-worker did.
try
{
} catch (OutOfMemoryException exception) {
Global.Insert("App.GetSettings;", exception.Message);
} catch (OverflowException exception) {
Global.Insert("App.GetSettings;", exception.Message);
} catch (InvalidCastException exception) {
Global.Insert("App.GetSettings;", exception.Message);
} catch (NullReferenceException exception) {
Global.Insert("App.GetSettings;", exception.Message);
} catch (IndexOutOfRangeException exception) {
Global.Insert("App.GetSettings;", exception.Message);
} catch (ArgumentException exception) {
Global.Insert("App.GetSettings;", exception.Message);
} catch (InvalidOperationException exception) {
Global.Insert("App.GetSettings;", exception.Message);
} catch (XmlException exception) {
Global.Insert("App.GetSettings;", exception.Message);
} catch (IOException exception) {
Global.Insert("App.GetSettings;", exception.Message);
} catch (NotSupportedException exception) {
Global.Insert("App.GetSettings;", exception.Message);
} catch (Exception exception) {
Global.Insert("App.GetSettings;", exception.Message);
}