3

I have a project I am creating and I am adding a reference to a class that generates an email where the exception happened and lots of good stuff.

My question is. If I was to put this in a method and call it in the Catch{} how would i do this for the whole project so i could just name the method in the catch and it would know on every page of the project.

var exceptionUtility = new genericExceptions();
exceptionUtility.genericSystemException(
ex,
Server.MachineName,
Page.TemplateSourceDirectory.Remove(0, 1) + Page.AppRelativeVirtualPath.Remove(0, 1),
ConfigurationManager.AppSettings["emailSupport"],
ConfigurationManager.AppSettings["emailFrom"],
string.Empty);
6
  • If you mean adding Try/Catch at every method calls or property calls, then i would say its a bad coding style. Exception handling at every level is costly. Commented Feb 25, 2013 at 10:03
  • I wrap my methods in try/Catch and add the above in every catch{} I want to make this better. Commented Feb 25, 2013 at 10:04
  • Jeffery Ritcher suggests that no where in your code base is wise enough to add try catch. Rather allow all exceptions to bubble up. Collect them at the top (App start perhaps Main() ). This way youll know every corner issues in your app plus quality increases and performance also no problem much. Try/catch at every level is kinda noise. Commented Feb 25, 2013 at 10:07
  • @zenwalker The performance impact of a try{}catch{} is low as long as you don't actually throw exceptions. Commented Feb 25, 2013 at 10:09
  • The code works great for problems in the projects and sends the problem and what line/page. I just wondered if I could just use it in a method and put the method in the Catch{} and reference it some how in the project and just keep calling the method in the Catch{} Commented Feb 25, 2013 at 10:12

1 Answer 1

1

on applicationError method you can do it.

Throw error in each catch block

private void ThrowingMethod()
{
    try
    {
        throw new InvalidOperationException("some exception");
    }
    catch
    {
        throw;
    }
    finally
    {

    }
}

and get it on the following event of Global.asax

void Application_Error(object sender, EventArgs e)
{

}

Here is a msdn link
http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/aspnet-error-handling

http://msdn.microsoft.com/en-us/library/24395wz3%28v=vs.100%29.aspx

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.