Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6665139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:41:29+00:00 2026-05-26T02:41:29+00:00

I log exceptions with Elmah and was wondering if the technique I am using

  • 0

I log exceptions with Elmah and was wondering if the technique I am using is good design?

Right now I catch and re throw exceptions that occur in various classes and methods, and log them to Elmah in the main try-catch block of the program.

// Main Program

try
{
   // Some code that fires off other classes, etc...
   MyTestClass myTestClass = new MyTestClass();
   myTestClass.Execute();   

}
catch(Exception ex)
{
   ErrorSignal.FromCurrentContext().Raise(ex);
}

// MyTestClass

    public class MyTestClass
    {
        public object ApiResult { get; set; }


        public string Execute()
        {            
            try
            {
                // execute some code
                // ....
                // set xml message
                ApiResult = "User information xml response";
            }
            catch (Exception ex)
            {
                // set xml message
                ApiResult = "something went wrong xml error response...";

                throw;
            }
        }

    }

Would it be better to log the exceptions where they occur? Another question, should I log errors that I can handle without catching exceptions? For example if something is null, should I do a test for that (if null…) and log a message in Elmah?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:41:30+00:00Added an answer on May 26, 2026 at 2:41 am

    Rather than manually logging an error using Elmah’s ErrorSignal class you should instead strive to let ELMAH log errors for you automatically, which occurs when the application’s Error event is raised.

    In your example there’s a serious problem with Main Program. Namely, it is swallowing exceptions, at least for the end user. Yes, the exception is getting logged in ELMAH but you are hiding the error from the user. The end user will think her form submission (or whatever) went through without error, when in actuality there was a grave problem.

    In short, try...catch blocks should only be used sparingly, such as in cases where you can recover from an error or when the error is a “minor” one and should not stop the workflow. But the majority of errors are real show stoppers and don’t have graceful workaround. For this majority you’d want to let the error percolate up to the ASP.NET runtime where ELMAH will automatically log it and where the user will see an error page, alerted them to the fact that an error has occurred.

    Check out this article of mine: Exception Handling Advice for ASP.NET Web Applications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Elmah to log exceptions. Elmah is great at logging request bodies if
I am using ELMAH to log unhandled exceptions in an ASP.NET Webforms application. Logging
I'm using Elmah to log exceptions for my website, everything seems to be all
We are using Elmah with MS SQL Server to log exceptions. The problem is
When I have my custom errors disabled, Elmah is taking all exceptions that occur
My application uses some third-party libraries. I need to log some exceptions that occur
We are using ELMAH to log the web application exception which works great!. Also
I'm using a filter to log exceptions thrown by actions which looks like this:
I'm looking to log unhandled javascript exceptions. Is there an event that fires when
I have been trying to parse Java exceptions that appear in a log for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.