Click here to Skip to main content
16,019,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dearsir,

i have a proble t6o handle exception in 3 trie web application i need to catch every exception based on exception we have populate error message.
and i have to write into .txt file all the exceptions.

thanks
karthik
Posted

So where is the problem? What have you tried?

Exception handling is an important part of any application.
If you have no idea about it, I would recommend you to get a book and start reading. You may also search for the topic and start reading the related articles.

If you have specific issues, come back here and ask. We will be happy to help someone who has tried.
 
Share this answer
 
You can catch errors in the Global.asax file

C#
protected void Application_Error(object sender, EventArgs e)
{
    //get reference to the source of the exception chain
    Exception ex = Server.GetLastError().GetBaseException();

    // Do something with the exception, write to log file etc
}


Have a look here at the Application_Error details

http://msdn.microsoft.com/en-us/library/aa479319.asp[^]

Personally, I use log4net and include logging within my component classes so I know what's happening within particular methods. You can always log at this level and let the exception be handled at the top of the stack using the Application_Error event handler or similar.
 
Share this answer
 
Hi,
here a sample code for exception handling in C#. but there is have lot of default exception methods are available in c#. do one thing you have to find out what type of exception occurred in catch black like DivideByZeroException and so on.. then only you will take decision in throw block...

cool,
senthil J
Softcrylic technology solutions india pvt ltd.,
C#
using System;
class MyClient
{
            public static void Main()
            {
                        int x = 0;
                        int div = 0;
                        try
                        {
                                    div = 100/x;
                                    Console.WriteLine("Not executed line");
                        }
                        catch(DivideByZeroException de)
                        {
                                    Console.WriteLine("Exception occured");
                        }
                        finally
                        {
                                    Console.WriteLine("Finally Block");
                        }
                        Console.WriteLine("Result is {0}",div);
            }
}
 
Share this answer
 
v2
Comments
Sandeep Mewara 23-Sep-10 11:46am    
Use PRE tags to format code part. It makes your answer readable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900