In the previous topics I explained already how to do some logging and validation with the Enterprise Library. Now I will shortly explain how to do some exception handling with the Enterprise Library.
The biggest advantage of using the enterprise library is the same as before. You can easily change settings of exception handling with the Enterprise Configuration Tool. You can also change settings if and how the exception needs to be logged in the event-viewer.
I used a windows application to show how it works but you can use it with WebPart in the same way.
First of all I created a Form with a textbox and a button. I will try to parse some random text to an integer.
The onclick event of the button has following code:
Later you will see in the screenshot of the Enterprise Library Configuration Tool that I used a custom exception handling method. To use a custom handler you need to create a new class and put following code in it:
The custom exception handler will show a messagebox with the message of the default exception.
As you see in the screenshot below I also set some logging to the exception handling block. So the exception will also be visible in the event-viewer.
With this configuration you get the behavior you can see below in some screenshots.
When I put some random text in the textbox and try to parse it I get a messagebox with the errormessage and there will also be a log in the event-viewer.