O'Reilly logo

Effective C#: 50 Specific Ways to Improve Your C#, Third Edition by Bill Wagner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5. Exception Practices

Errors happen. Despite our best efforts, our programs encounter situations we didn’t anticipate. Throughout the .NET Framework, methods either succeed, or they indicate their failure by throwing an exception. The libraries and applications you write will be easier to use and extend if you follow this same practice. Making your code robust when exceptions are thrown is a key skill for every C# developer.

Your code will call methods that throw exceptions. Your code must behave in a well-known manner when it calls a method that throws an exception.

Your code may also throw exceptions directly. The .NET Framework Design Guidelines recommend throwing exceptions in all cases when your method does not do what was asked. You must ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required