Page 114 - DCAP312_WEB_TECHNOLOGIES_II
P. 114

Web Technologies-II



                   Notes         Introduction

                                 One of the main characters of ASP.NET over ASP is its new error handling features. The only
                                 way to imprison errors in the ASP/VBScript was using the "On Error Resume Next" declaration
                                 and scrutiny each line for an error with "If Err. Number <> 0 Then “statements. Developers who
                                 were using JScript instead of the VBScript at the server-side where lucky. They have had access
                                 to the "Try. Catch" statements provided by JScript. Well it is all over now. Now all the .NET
                                 enabled languages support better error handling statements including VB.NET. Now, VB.NET
                                 supports the "Try...Catch" statement. On top of this ASP.NET configuration file also supports
                                 ASP.NET level error handling.
                                 We always to create a problem-free function, one that always behaves as expected. In reality,
                                 many things can go wrong while a program is running. As an application developer, you can
                                 anticipate as much bad behaviour as possible so you can take appropriate actions. To assist
                                 you with dealing with errors, the Visual Basic language provides many keywords, operators,
                                 and techniques.

                                 6.1 Logics of Error Handling

                                 When an unhandled immunity propagates, the user may well be redirect to an error sheet using
                                 different ASP.NET constitution settings. However, such a redirection may be prohibited in the
                                 first place by treatment the exceptions that get thrown. Error handling in ASP.NET therefore,
                                 may be divided into two separate logics:
                                    •  Redirecting the user to an error page when errors go unhandled.

                                    •  Handling exceptions when they get thrown.
                                 6.1.1 Redirecting the User to an Error Page

                                 There are two different scopes where we could specify which page the user has to be redirected
                                 to, when errors go unhandled:

                                    •  Page level (applies to errors that happen within a single page).
                                    •  Application level (applies to errors that happen anywhere in the application).
                                 Page Level
                                 Use the error Page attribute in the web form.

                                 This attribute defines the page the user should be redirected to when an unhandled exception
                                 occurs in that specific.

                                 The error Page attributes maps to the Page. Error Page property, and hence may be set
                                 programmatically. The value may optionally include query string parameters. If no parameters
                                 are added, ASP.NET would automatically add one with the name aspx error path. This parameter
                                 would hold the value of the relative URL to this page, so that the error page would be able to
                                 determine which page caused the error.
                                 If a value is specified in this attribute (or property) and an unhandled exception occurs in the
                                 page, the Page class would automatically perform a redirect to the specified page. If a value is
                                 not specified, the exception is assumed to be unhandled, wrapped in a new Http Unhandled
                                 Exception and then thrown, propagating it to the next higher level.
                                 Application Level

                                 Use the custom Errors section in web.config.



        108                               LOVELY PROFESSIONAL UNIVERSITY
   109   110   111   112   113   114   115   116   117   118   119