Latests

Gotta Catch ‘Em All


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);

Well, I guess that if they ever need to add different code paths, they’re halfway there.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button

Adblock Detected

Please consider supporting us by disabling your ad blocker