Pre-Assessment Questions: Error Handling and Debugging

Download as pps, pdf, or txt
Download as pps, pdf, or txt
You are on page 1of 25

Error Handling and Debugging

Pre-Assessment Questions
1. Identify the correct description of a Runtime-Callable Wrapper.

a. A Runtime-Callable Wrapper manages the whole operation of a COM


component.
b. A Runtime-Callable Wrapper is a number used to identify COM
components uniquely.
c. A Runtime-Callable Wrapper is a language‑independent architecture
that defines specifications for component interoperability.
d. A Runtime-Callable Wrapper is a standard mechanism to register and
discover a Web service.

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 1 of 25


Error Handling and Debugging

Pre-Assessment Questions (Contd.)


2. The BinaryWrite method of the _____________ object is used to write binary
data to the client.
a. Request
b. Application
c. Session
d. Response

3. A __________arrow means that the control resides on the server side and
that the control is accessible from the server-side code.
a. Yellow
b. Red
c. Blue
d. Green

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 2 of 25


Error Handling and Debugging

Pre-Assessment Questions (Contd.)


4. The default timeout period for a session is ________________ minutes.

a. 10
b. 40
c. 60
d. 20

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 3 of 25


Error Handling and Debugging

Pre-Assessment Questions (Contd.)


5. Consider the following statements:
• Statement A: The AlternatingItemTemplate template represents the
collection of elements and controls that are rendered for every
alternating row in the data source.
• Statement B: The HeaderTemplate represents the collection of elements
and controls that are accessed once before any other item is accessed
in the control.
Select the correct option.
a. Statement A is True and statement B is False.
b. Statement B is True and statement A is False.
c. Both the statements are True.
d. Both the statements are False.

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 4 of 25


Error Handling and Debugging

Solutions to Pre-Assessment
Questions
1. a. A Runtime-Callable Wrapper manages the whole operation of a COM
component.
2. d. Response
3. d. Green
4. d. 20
5. c. Both the statements are True.

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 5 of 25


Error Handling and Debugging

Objectives
In this lesson, you will learn to:

• Identify the types of errors in a Web application


• Implement page-level error handling
• Implement application-level error handling
• Add error messages to an event log
• Test Web applications
• Design a unit test plan for Web application
• Debug a Web application
• Use tracing in a Web application
• Add and remove trace listeners
• Use trace switches

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 6 of 25


Error Handling and Debugging

Implementing Error Handling In Web


Based Applications

• The following types of errors occur in a Web application:


• Configuration errors
• Parser errors
• Compilation errors
• Runtime errors

• Errors in ASP.NET applications can be handled at two levels:


• Page level error handling
• Application level error handling

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 7 of 25


Error Handling and Debugging

Implementing Error Handling In Web


Based Applications (Contd.)
• Page level error handling:
• Is used to handle and capture unforeseen errors in ASP.NET pages
• Uses the ErrorPage property of the Page object to trap them
• Uses two types of methods to solve these errors:
• Using the Try-Catch block
• Using the Page_Error subroutine

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 8 of 25


Error Handling and Debugging

Implementing Error Handling In Web


Based Applications (Contd.)
• Application-Level error handling:
• Enables you to handle errors in ASP.NET pages, irrespective of where they
occur in the application
• The Application_Error event of the global.asax file is used for application-
level error handling
• Uses <customErrors> tag to restrict the amount of error information being
displayed

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 9 of 25


Error Handling and Debugging

Implementing Error Handling In Web


Based Applications (Contd.)
• You can create an entry for your application in the event log for an application
to store the error information related to an application.
• You need to import the System.Diagnostics namespace in your application to
write to an event log.
• Three log files exist on a server: Application, System, and Security. The
Application log file is used by the applications and services when the Security
log file is used by the system for generating success or failure audit events.

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 10 of 25


Error Handling and Debugging

Implementing Error Handling In Web


Based Applications (Contd.)
• The steps for writing to an event log are:
• Open the application’s Global.asax file from the Solution Explorer
window.
• Switch to the code view of the Global.asax file
• Add the code for writing the error message to the event log under the
Application_Error event.
• In the given code, an object Eventlog of type EventLog is created.
• The string Message stores a static text and the requested page path.
• A check is done to verify whether an event source with the name
MyLogFile already exists.

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 11 of 25


Error Handling and Debugging

Implementing Error Handling In Web


Based Applications (Contd.)
• After the event log is created, the error message is written to the event log
MyLogFile.
• To view the entries of an event log, click
StartProgramsAdministrative ToolsEvent Viewer.
• The Event Viewer containing the event logs listed in the left pane is
displayed. The event log MyLogFile that you created is also displayed in
the list.

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 12 of 25


Error Handling and Debugging

Testing Web Based Applications


• When an application is developed, it should be ensured that the application is
defect-free. To produce defect-free applications, various levels of testing
should be performed on the application.
• Following are the benefits of testing an application:
• Cost cutting
• Results in applications that works as desired
• Controls the total cost of ownership
• Various types of testing are:
• Requirements testing
• Usability testing
• Unit testing
• Integration testing
• Regression testing

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 13 of 25


Error Handling and Debugging

Testing Web Based Applications


(Contd.)
• Following are the guidelines for effective testing:
• Organizing the testing effort at the right stage with proper planning
• The testing should be planned as per the requirement specifications. The
test cases should be designed while the requirements specifications are
being written. A test case consists of sample data and the corresponding
output that are calculated manually.
• Develop a test plan to ensure that all the modules are covered. There are
two approaches to testing:
• Waterfall approach
• Evolutionary approach

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 14 of 25


Error Handling and Debugging

Testing Web Based Applications


(Contd.)
• Waterfall Approach:
• Is followed for testing application and consists of various phases.
• Phases cover requirement analysis, design and specifications
requirements, coding, final testing, and release.
• Is best suited for small projects having limited complexity.

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 15 of 25


Error Handling and Debugging

Testing Web Based Applications


(Contd.)
• In the Evolutionary Approach:
• A modular piece or unit of an application is developed.
• Application is tested, fixed, and then another small piece is added to
incorporate functionality.
• Finally, the two units are tested as an integrated component, thus
increasing the complexity as the plan proceeds.
• Some of the advantages of Evolutionary approach are:
• Design can be defined to make the application better
• Development can be stopped any time, when functionality is added in
priority order.
• New sections can be added to the test plan.
• With the help of small modular pieces incorporated in the final test plan,
bugs can be located easily.

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 16 of 25


Error Handling and Debugging

Debugging Web Based Applications


• The various tools available in the Visual Studio .NET debugging environment
are:
• Setting Breakpoints
• Disabling Debug Mode
• Using the Object Browser to View Definitions
• Using the Class Viewer
• Using the Output Window

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 17 of 25


Error Handling and Debugging

Implement Tracing In A Web Based


Application
• Tracing is a debugging method that enables you to output debugging
information about a single request.
• ASP.NET provides two levels of tracing:
• Page-Level tracing
• Application-Level tracing
• Page-level tracing:
• Is used to generate diagnostic information at the end of the normal page
rendering.
• Displays the following information for a page:
• Request details, Trace information
• Control tree, Cookies collection
• Headers Collection
• Server variables

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 18 of 25


Error Handling and Debugging

Implement Tracing in a Web Based


Application (Contd.)
• Application tracing is used to trace information for every page running in an
application.
• A special page named Trace.axd is used to view this trace information.
• Following elements are used to change the settings of application-level trace:
• enabled
• requestLimit
• pageOutput
• traceMode
• localOnly

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 19 of 25


Error Handling and Debugging

Implement Tracing in a Web Based


Application (Contd.)
• The Trace property of the page class returns a Trace object.
• Trace object is an instance of Tracecontext class.
• The Trace object provides a set of methods and properties that help trace the
execution of your application.
• Following are the properties of the Trace object:
• IsEnabled
• TraceMode
• Following are the methods of the Trace object:
• Warn
• Write
• The Trace object is used as an alternative to the Response object for
debugging

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 20 of 25


Error Handling and Debugging

Implement Tracing in a Web Based


Application (Contd.)
• Trace Listeners are used to collect, store, and route tracing messages. You
can also use trace listeners to redirect the tracing information to logs,
windows, or text files.
• ASP.NET provides three types of predefined trace listeners:
• TextWriterTraceListener
• EventLogTraceListener
• DefaultTraceListener

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 21 of 25


Error Handling and Debugging

Implement Tracing in a Web Based


Application (Contd.)
• Trace Switches are used to control the tracing output.
• Following are the two types of trace switches:
• BooleanSwitch
• TraceSwitch
• Trace switches are:
• Initialized
• Configured
• Compiled conditionally to include tracing code

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 22 of 25


Error Handling and Debugging

Summary
In this lesson, you learned:

• The errors that occur in a Web application are categorized as:


• Configuration errors
• Parser errors
• Compilation errors
• Run-time errors
• There are two methods of error handling:
• Page level error handling
• Application level error handling

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 23 of 25


Error Handling and Debugging

Summary (Contd.)
• The different types of testing are:
• Requirements testing
• Usability testing
• Unit testing
• Integration testing
• Regression testing
• Following are the guidelines for testing:
• Organizing the testing effort
• The testing should be planned as per the requirement specifications
• Develop a test plan to ensure that all the modules are covered
• The two approaches for testing are:
• Water-fall approach
• Evolutionary approach

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 24 of 25


Error Handling and Debugging

Summary (Contd.)
• Tracing is a debugging method that enables you to display the debugging
information about a request.
• There are two levels of tracing:
• Page-level tracing
• Application-level tracing
• Trace Listeners are used to collect, store, and route tracing messages. You can
also use trace listeners to redirect the tracing information to logs, windows, or
text files.
• Trace Switches are used to control the tracing output.

©NIIT Developing Web Applications Using ASP.NET Lesson 3B / Slide 25 of 25

You might also like