Programming Tutorial On The Way

free online programming resource on dotnet, csharp, web related topics

You have a method, property, or indexer that requires the correct value or set of values to be passed in to it (e.g., cannot be null, must be within a numeric range or a set of numeric ranges, the enumeration value must be a valid value in the enumeration). If an incorrect value is passed in to the method, it must inform the application and handle the invalid value gracefully. This is especially for public method that can be accessed from outside. Read the rest of this entry »

Popularity: 2% [?]

Consider throwing exceptions instead of returning HRESULTs or some other type of error code. With well-placed exception handling code, you should not have to rely on methods that return error codes such as an HRESULT or a Boolean true/false to correctly handle errors, which makes for much cleaner code. Another benefit is that you do not have to look up any HRESULT values or any other type of error code to understand the code. However, the biggest advantage is that when an exceptional situation arises, you cannot just ignore it as you can with error codes. Read the rest of this entry »

Popularity: 2% [?]

To improve performance, you should programmatically handle the case when an exception could be thrown versus catching the exception after it is thrown. For example, if a method has a good chance of returning a null value, you could test the returned value for null before that value is used, as opposed to using a try-catch block and allowing the NullReferenceException to be thrown. Remember that throwing an exception has a negative impact on performance and exception-handling code has no noticeable impact on performance, as long as an exception is not thrown. To illustrate this, we take a method that uses exception handling code to handle the NullReferenceException: Read the rest of this entry »

Popularity: 2% [?]

The .NET Framework allows all .NET languages to take advantage of structured exception handling. Structured exception handling provides a control structure that includes exceptions, protected blocks of code, and filters to allow your code to handle exception robustly and efficiently. You can use try, catch, and finally blocks to detect exceptions thrown within your code and react to them appropriately. Read the rest of this entry »

Popularity: 6% [?]