Topics to be covered 1 Exceptional handling 2

Topics to be covered 1. Exceptional handling 2. Debugging 3. Tracing

Exception handling 1. The languages supported by. NET implementing exception handling 2. Understand different Types of errors 3. Catching and handling exceptions • i. System. Exception class is the base class for all exceptions. • ii. Supports in. Net by using C# and VB. net. • iii. These languages are using try catch finally blocks to implemnt the exception handling • iv. Try , catch and finally blocks may differ in VB. net and C# by case • v. when an exception occurs the emainder of the code in try block skipped and some code in catch block can be run to deal with error. • vi. code can have multiple catch clocks that deal with specific exeptions only the first block that matches the exception type will fire. hence order is an important. • vii. A try or catch block can be followed by a finally block. code in finally block always fired. • vii. Catch and finally blocks are optional. example

• It is a methodology to identify the errors and handle errors that occur at run time. • By handling these errors u can present your users a friendly error message. Back

Types of errors • Syntax errors: Errors caused by writing codes that do not follow the rules of the lang. ex: -misspelled keyword. 1. 2. also called as compile errors and easily can we find In. NET u can through error list from view menu • Logical errors: errors due to incorrect implementation of algorithms. 1. these errors harder to find. 2. unexpected result • Runtime errors: errors that happen after the codes are compiled and executed. 1. occurs at runtime and difficult to track. 2. example division by zero back

• • • • • protected void Page_Load(object sender, Event. Args e) { Mail. Message mymesg = new Mail. Message(); mymesg. Subject = "exception hand"; mymesg. Body = "test message"; try { mymesg. From = new Mail. Address("rndhth@yahoo. com"); mymesg. To. Add(new Mail. Address("rndhth@yahoo. com")); Smtp. Client MYSMPT = new Smtp. Client("NOT EXIXTED"); MYSMPT. Send(mymesg); Label 1. Text = "message sent"; } catch (Smtp. Exception) { Label 1. Text = "an error"; } } } Back to topics

Debugging • Process of finding and fixing bugs in your code. • The harder bugs requires the execution environment of your program by using Visual Studio. NET Debugging Tools.

Debugging tools 1. setting break points: allows you to examine varibles and trace the execution flow of your application. 2. Enabling and disabling debug mode. : modify web. config file with <compilation > eement <compilation defaultlanguge=“c#” debug=true/> remember to set debug ttribute to false when deploying u r application continue…

3. Viewing definitions using the object browser: by pressing CTRL+ALT+J 4. Using the class viewer: besides object browser u can also use the Class viewer. To launch type Win. CV at the command prompt.
- Slides: 8