Finding Handled Exceptions while debugging time

Kotra.Ramakrishna
Posted by in .NET Framework category on for Beginner level | Points: 250 | Views : 4411 red flag

This article will help beginners. Handling exceptions finding

Introduction

This article mainly focus on how to find handled exceptions. While debugging code, we easily find unhandled exceptions. But how to find handled exceptions, please look at below steps

Prerequisite

In order to understand this article basic knowledge of C# & VS. For demo purpose i am using console application.


Creating Simple Console Application.

Go to File New-> Project, it will display window , form  that window left side templates Select Visula C#, and then come to right side select Console Application. It will create one static main method. Please refer below code

Block of code should be set style as "Code" like below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HandlingExceptionsDebugging
{
class Program
{
static void Main(string[] args)
{

}
}
}

By default visual studio will create this code.

Now create two methods. Please refer below code.

public void UnhandledException()
{
throw new Exception("Unhandled Exception");
}

public void HandledException()
{
try
{
throw new Exception("Exception throwing");
}
catch (Exception)
{

}
}
These two methods are very simple. one is unhandled exception method, second one is handling exception.
Now go to  Main method, create Program object, and call these tow methods. Press F5 button.

Please look at below code

        static void Main(string[] args)
{
Program p = new Program();
p.HandledException();
p.UnhandledException();
Console.Read();
}

HandledException method also throwing exception but, it won't notify. Directly cursor (Exception occur) UnhandledException method.

Question is how we will find Handled Exceptions?

Go to Debug menu->Select Exception menu item it will display pop up window, Select all checkboxes below Thrown.

Please refer below screen

now run application press(F5) . now we are able to find handled exceptions also.  Cursor will stops HandledException method also.

Hope this article will useful for beginners.

Page copy protected against web site content infringement by Copyscape

About the Author

Kotra.Ramakrishna
Full Name: rama krishna
Member Level: Starter
Member Status: Member
Member Since: 9/10/2012 12:03:56 AM
Country: India
Thanks & Regards Ramakrishna.k
http://www.dotnetfunda.com

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)