.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links


Posted By: Faizal     Posted Date: December 17, 2009    Points: 2   Category :.NET Framework
Every self-respected programmer should include exception handling techniques. Sometimes your application will generate an error. Regardless of who was responsible for this error, the programmer or the user, it is up to the first to include the necessary exception handling techniques to keep his/her program from crashing. The .Net environment provides useful techniques for avoiding disastrous errors such as try-catch statements and user-defined exceptions.

View Complete Post

More Related Resource Links

Global Exception Handling with ASP.NET

After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

SQL Server 2005 Try and Catch Exception Handling

I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

Error while using exception handling block el 4.1


Hi Folks,


i am trying to use tyhe exception handling block of Enterprise library 4.1.


I just createda polisy and used IndexOutOfRangeException and added a replace handler and a logging handler to it.

I am using the NotifyRethrow PostHandlingAction to the exception.


During runtime I am getting an exception on the HandleException event, The exception is added below:



Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 42:             catch (Exception ex)
Line 43:             {
Line 44:                 bool reThrow = ExceptionPolicy.HandleException(ex, "ReplacePolicy");
Line 45:         

Data Points: SQL Server 2005 XML Support, Exception Handling, and More


SQL Server 2005 includes several important improvements to the Transact-SQL (T-SQL) language. One added feature is a new kind of trigger that fires when data definition language (DDL) statements run.

John Papa

MSDN Magazine May 2006

Error Handling: Throwing Custom Exception Types from a Managed COM+ Server Application


Exception handling semantics in .NET are based on type, so you can create custom exceptions that have their own properties and methods. In .NET, exceptions are first-class citizens, and since they're the built-in error handling mechanism, all .NET-compliant languages must support exceptions. In addition, COM+ services are available to .NET code as Enterprise Services, so you can leverage exceptions in your Enterprise Services design.In this article the author describes custom exceptions, throwing exceptions across COM interop boundaries, and working with Enterprise Services.

Bob DeRemer

MSDN Magazine March 2004

Bad email address exception handling

 I have a form that used to send an email to someone who had posted  a listing on my site, with a copy to the sending user. The code below is intended to catch the exception that occurs when email address of the person posting the listing (TxtBxTo.Text) is not valid, and also intended to catch the (unlikely) event that the user has entered and confirmed an invalid email (TxtBxEmail.Text) for himself on the form. I have tested this code for all combinations of valid and invalid email addresses for the listing poster and the user filling out the form and sending the email Everything works fine except for the situation where the email address for the listing poster is valid but that of the user  is invalid. In this situation I am getting the message on the ConfirmResaleEmail.aspx page that says: "Your message has been sent to the contact person, with a copy to you. " when I should be getting "Woops, it looks like your own email failed when we tried to send you your copy. " I am hoping some sharp-eyed person can spot the problem.  Here is the code:         ' this sends email from a user with email TxtBxEmail to the contact perons listed in TxtBxTo        msg = New MailMessage(TxtBxEmail.Text, TxtBxTo.Text, TxtBxSubject.Text, sb.ToString())    &n

Exception handling in EventHandlers, Sharepoint

What i am doing is when a user upload or edit any doc in a doc library then automatic mail should go to some users. I have written mail sending code in ItemAdded event . My problem is if any exception occurs in my Mail code i want to show that to the user so that he can manually send mails to the concerned users. I have tried using Properties.Cancel=true; but it is not working neither i am able to redirect the user to some custom error page.  I know if i use ItemAdding Event then these codes will work  but i do not want to cancel the document uploading process . Because if i am able to throw the exception then user can manually send the mail. Please suggest how can i show exception message to the user.

Global Exception Handling

Hi,   I followed thsi link to implement gloabl exception Handling in winforms app   http://msmvps.com/blogs/deborahk/archive/2009/09/02/global-exception-handler-winforms.aspx?CommentPosted=true#commentmessage   I am geting thwe following errors on this line in the main   Public Shared Sub Main() Application.ThreadException += New ThreadExceptionEventHandler(Application_ThreadException) ' --Errors here on this line   Dim dlg As New frm_Login   If dlg.ShowDialog() = DialogResult.OK Then   Dim frm As New frmMDI_Manager frm.ShowDialog()   End If   End Sub   Error 7 'Public Shared Event ThreadException(sender As Object, e As System.Threading.ThreadExceptionEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.  Error 8 Delegate 'System.Threading.ThreadExceptionEventHandler' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor.  Can any one suggest how to get it working? Thanks  

Exception Handling for oracle & sqlServer

Hi,   My application is working with two databases based on the data providers, now i want to implement the enterprise library exception handling mechanism.. please help me : 

How to create a Custom Exception Handler using Micorosft Exception Handling Application Block?

Dear Friends,Can any one let me know "How to create a Custom Exception Handler using Microsoft Exception Handling Application Blocks"I will be having a set of Exceptions which will be getting maintained in an XML File along with the User Friendly Messages for a particular Exception. Whenever an Exception occurs in the projects first it need to check with the Exceptions present in the XML File and need to display the concerned user friendly message for that particular exception to the user..I am not able to get an idea on "How to start with the Microsoft Exception Handler Application Block" to achieve this". Please help me in this regard...Thanks and Regards,G.V.N.Sandeep.

unable to config the enterprise library exception handling for oracle

Hi unable to config the enterprise library exception handling for oracle any help?   Thanks in advance :-)

handling dll Exception


In WPF application, iam using third party dll (Mapsuite for Maps).

In some scenarious an unhandled nullReferenceException is occuring in dll,

try catch is not able to handled that exception.

how to handled that exception.

PS.Shakeer Hussain Hyderabad

Exception thrown when handling Window.Loaded event


Why is the exception assistant not "fired" in a debugging session when a Window.Loaded eventhandler calls code which throws an exception ?
        private void Window_Loaded(object sender, RoutedEventArgs e)
            //Application.Current.DispatcherUnhandledException +=
               new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);
            int a = 1;
            int b = 0;
            int c = a / b;

        void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)

Removing the comment signs (//) thus presenting an UnhandledException handler devinately makes the assistant "firing".
Is this behaviour by desi

Wizard not going to the next step after handling an exception



I am using the standard createuser wizard (but got same issue with other wizard) and in the CreatedUser event an exception is raised causing the wizard not to reach the next step.  If no exception are raised the wizard behave as expected.  I have tried to force the wizard to move to the next step using CreateNewMember.MoveTo(this.CompleteWizardStep1); as an exemple but still the web page is in waiting stage for about 5 to 10 mins before it finally reach the final step.  I have tried to deal with the exception in the routine it occured or throw it back to the CreatedUser event and deal with it there but nothing changes as of to the move to the next step in the wizard.

I have spend hours trying to get around this without any success, so any help would be greatly appreciated.

Strongly typed dataset exception handling


Hey everyone,

I'm currently working on a 3-tier ASP.NET application (UI, BLL & DAL). The DAL uses a strongly typed dataset that I've created with the VS Dataset Wizard. My question is, what is the best way to handle exceptions originating from the BLL and DAL classes. I googled a bit and it seems that the most commonly used practice is to create DALException and BLLException classes and throw your own message. Is this the way forward? Could you please indicate how this can be done for an automatically generated DAL? What are the best practices? Examples with code are highly appreciated!!



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend