- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
choosing an exception handling strategy in Visual Basic .NET
choosing an exception handling strategy Drawing Code39 In Visual Basic .NET Using Barcode drawer for VS .NET Control to generate, create Code 39 Full ASCII image in .NET applications. www.OnBarcode.comDecoding Code-39 In Visual Basic .NET Using Barcode reader for .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comch a pter thr ee
Encode Bar Code In VB.NET Using Barcode printer for VS .NET Control to generate, create barcode image in .NET framework applications. www.OnBarcode.comBar Code Scanner In Visual Basic .NET Using Barcode reader for .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comRemember that the whole idea of using the Exception Handling block is to implement a strategy made up of configurable policies that you can change without having to edit, recompile, and redeploy the application. For example, the block allows you (or an administrator) to: Add, remove, and change the types of handlers (such as the Wrap, Replace, and Logging handlers) that you use for each exception policy, and change the order in which they execute. Add, remove, and change the exception types that each policy will handle, and the types of exceptions used to wrap or replace the original exceptions. Modify the target and style of logging, including modifying the log messages, for each type of exception you decide to log. This is useful, for example, when testing and debugging applications. Decide what to do after the block handles the exception. Provided that the exception handling code you write checks the return value from the call to the Exception Handling block, the post-handling action will allow you or an administrator to specify whether the exception should be thrown. Again, this is extremely useful when testing and debugging applications. The Exception Handling block provides two ways for you to manage exceptions. You can use the Process method to execute any method in your application, and have the block automatically perform management and throwing of the exception. Alternatively, if you want to apply more granular control over the process, you can use the HandleException method. The following will help you to understand which approach to choose. The Process method is the most common approach, and is useful in the majority of cases. You specify either a delegate (the address of a method) or a lambda expression that you want to execute. The Exception Handling block executes the method or expression, and automatically manages any exception that occurs. You will generally specify a PostHandlingAction of ThrowNew Exception so that the block automatically throws the exception that results from executing the exception handling policy. However, if you want the code to continue to execute (instead of throwing the exception), you can set the PostHandlingAction of your exception handling policy to None. The HandleException method is useful if you want to be able to detect the result of executing the exception handling policy. For example, if you set the PostHandlingAction of a policy to NotifyRethrow, you can use the return value of the HandleException method to determine whether or not to throw the exception. You can also use the HandleException method to pass an exception to the block and have it return the exception that results from executing the policy which might be the original exception, a replacement exception, or the original exception wrapped inside a new exception. You will see both the Process and the HandleException techniques described in the following examples, although most of them use the Process method. Drawing USS Code 39 In Visual C#.NET Using Barcode encoder for Visual Studio .NET Control to generate, create Code-39 image in .NET applications. www.OnBarcode.comCode-39 Creator In .NET Framework Using Barcode maker for ASP.NET Control to generate, create Code 3/9 image in ASP.NET applications. www.OnBarcode.comprocess or handle exception
Printing Code 3/9 In .NET Framework Using Barcode drawer for .NET Control to generate, create Code 39 Full ASCII image in .NET applications. www.OnBarcode.comMake ANSI/AIM Code 128 In Visual Basic .NET Using Barcode encoder for Visual Studio .NET Control to generate, create Code 128C image in .NET applications. www.OnBarcode.comer ror m a nagement m a de exceptiona lly easy
Print Code 39 In VB.NET Using Barcode encoder for Visual Studio .NET Control to generate, create Code-39 image in .NET applications. www.OnBarcode.comMake Barcode In Visual Basic .NET Using Barcode generation for .NET framework Control to generate, create bar code image in VS .NET applications. www.OnBarcode.comUsing the Process Method The Process method has several overloads that make it easy to execute functions that return a value, and methods that do not. Typically, you will use the Process method in one of the following ways: To execute a routine or method that does not accept parameters and does not return a value: Bar Code Generator In Visual Basic .NET Using Barcode printer for .NET framework Control to generate, create barcode image in .NET framework applications. www.OnBarcode.comIndustrial 2 Of 5 Encoder In VB.NET Using Barcode generator for VS .NET Control to generate, create 2/5 Industrial image in .NET applications. www.OnBarcode.comexManager.Process(method_name, "Exception Policy Name"); Data Matrix ECC200 Encoder In Java Using Barcode encoder for Java Control to generate, create DataMatrix image in Java applications. www.OnBarcode.comPaint Linear 1D Barcode In Visual Studio .NET Using Barcode generator for .NET framework Control to generate, create Linear Barcode image in .NET applications. www.OnBarcode.com To execute a routine that does accept parameters but does not return a value: Print EAN128 In Visual Studio .NET Using Barcode maker for Reporting Service Control to generate, create EAN 128 image in Reporting Service applications. www.OnBarcode.comCode 3 Of 9 Encoder In None Using Barcode drawer for Office Word Control to generate, create ANSI/AIM Code 39 image in Office Word applications. www.OnBarcode.comexManager.Process(() => method_name(param1, param2), "Exception Policy Name"); Encode GS1 - 12 In VS .NET Using Barcode drawer for Reporting Service Control to generate, create GTIN - 12 image in Reporting Service applications. www.OnBarcode.comCode39 Creation In Java Using Barcode drawer for Java Control to generate, create Code 3/9 image in Java applications. www.OnBarcode.com To execute a routine that accepts parameters and returns a value: Creating Linear Barcode In Visual Studio .NET Using Barcode generation for ASP.NET Control to generate, create Linear Barcode image in ASP.NET applications. www.OnBarcode.comANSI/AIM Code 39 Generator In Objective-C Using Barcode printer for iPhone Control to generate, create Code 39 Full ASCII image in iPhone applications. www.OnBarcode.comvar result = exManager.Process(() => method_name(param1, param2), "Exception Policy Name"); To execute a routine that accepts parameters and returns a value, and to also
supply a default value to be returned should an exception occur and the policy that executes does not throw the exception. If you do not specify a default value and the PostHandlingAction is set to None, the Process method will return null for reference types, zero for numeric types, or the default empty value for other types should an exception occur. var result = exManager.Process(() => method-name(param1, param2), default_result_value, "Exception Policy Name"); To execute code defined within the lambda expression itself: exManager.Process(() => { // Code lines here to execute application feature // that may raise an exception that the Exception // Handling block will handle using the policy named // in the final parameter of the Process method. // If required, the lambda expression defined here // can return a value that the Process method will // return to the calling code. }, "Exception Policy Name"); The Process method is optimized for use with lambda expressions, which are supported in C# 3.0 on version 3.5 of the .NET Framework and in Microsoft Visual Studio 2008 onwards. If you are not familiar with lambda functions or their syntax, see http:// msdn.microsoft.com/en-us/library/bb397687.aspx. For a full explanation of using the HandleException method, see the Key Scenarios topic in the online documentation for Enterprise Library 4.1 at http://msdn.microsoft.com/en-us/library/dd203198.aspx.
|
|