Click here to Skip to main content
12,063,909 members (62,311 online)
Click here to Skip to main content

Stats

38.2K views
945 downloads
75 bookmarked
Posted

Automatic Error Handling

, 17 Mar 2008 CPOL
Handle web and WinForms exceptions automatically.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
	protected void Page_Load( object sender, EventArgs e )
	{

	}

	protected void _button_Click( object sender, EventArgs e )
	{
		SubOne();
	}


	private void GenerateException()
	{
		System.Collections.Specialized.NameValueCollection nvc = null;
		_textBox.Text = nvc.Count.ToString();
	}

	private void SubOne()
	{
		try
		{
			SubTwo();
		}
		catch( Exception ex )
		{
			throw new InvalidCastException( "SubOne call failed!", ex );
		}
	}

	private void SubTwo()
	{
		try
		{
			GenerateException();
		}
		catch( Exception ex )
		{
			throw new DataException( "SubTwo handled an exception!", ex );
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Andy Searls
Software Developer (Senior) Belami
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160204.4 | Last Updated 17 Mar 2008
Article Copyright 2008 by Andy Searls
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid