Dragan
Dragan

Reputation: 3743

Do I need to use exception handling if I use ELMAH?

Do I need to wrap my code with try...catch statements if I use ELMAH?

I have the following code:

namespace ElmahTestApp.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            try
            {

                DateTime date = DateTime.Parse("asdasdasd");

            }
            catch (Exception ex)
            {
            }
            return View();
        }

    }
}

The view shows up (as expected) however the exception does not get logged. Any suggestions? THanks in advance!

Upvotes: 1

Views: 91

Answers (2)

Doozer Blake
Doozer Blake

Reputation: 7797

Look at ErrorSignal. In your case, you'd do something like

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

Upvotes: 2

SLaks
SLaks

Reputation: 887195

If you want your code to handle exceptions gracefully (eg, fallback to something else), you still need catch blocks.

Upvotes: 3

Related Questions