Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling Error "WebDev.WebServer.Exe has stopped working"

Is there a way to handle the error "WebDev.WebServer.Exe has stopped working" in ASP.NET and keep the page running or even the just the WebServer running? Or is this an impossible task and is essentially like asking how to save someone's life after they've died?

I have the error-causing code inside a try/catch block, but that doesn't make a difference. I've also tried registering a new UnhandledExceptionEventHandler, but that didn't work either. My code is below in case I'm doing something wrong.

Also to be clear, I'm not asking for help on how to prevent the error; I want to know if and when the error happens if there's anything I can do to handle it.

UPDATE 1: TestOcx is a VB6 OCX that passes a reference of a string to a DLL written in Clarion.

UPDATE 2: As per @JDennis's answer, I should clarify that the catch(Exception ex) block is not being entered either. If I removed the call to the OCX from the try\catch block it still won't reach the UnhandledException method. There are essentially two areas that don't ever get executed.

UPDATE 3: From @AndrewLewis, I tried to also add a regular catch block to catch any non-CLS compliant exceptions, and this did not work either. However, I later found that since .NET 2.0 on, all non-CLS exceptions are wrapped inside RuntimeWrappedException so a catch (Exception) will catch non-CLS compliant exceptions too. Check out this other question here for more info.

public bool TestMethod()
{
    AppDomain.CurrentDomain.UnhandledException +=
        new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

    string input = "test";
    string result = "";
    try
    {
        TestOcx myCom = new TestOcx();
        result = myCom.PassString(ref input); // <== MAJOR ERROR!
        // do stuff with result...
        return true;
    }
    catch (Exception ex)
    {
        log.Add("Exception: " + ex.Message); // THIS NEVER GETS CALLED
        return false;
    }
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    // THIS NEVER GETS CALLED
    try
    {
        Exception ex = (Exception)e.ExceptionObject;
        log.Add("Exception: " + ex.Message);
    }
    catch (Exception exc)
    {
        log.Add("Fatal Non-UI Error: " + exc.Message);
    }
}
like image 824
DanM7 Avatar asked Sep 26 '12 22:09

DanM7


1 Answers

You should try catching non-CLS compliant exceptions to make sure nothing is being thrown (keep in mind you don't want to do this in production, always be specific!):

try
{
    TestOcx myCom = new TestOcx();
    result = myCom.PassString(ref input); // <== MAJOR ERROR!
    // do stuff with result...
    return true;
}

catch (Exception ex)
{
    log.Add("Exception: " + ex.Message); // THIS NEVER GETS CALLED
    return false;
}
catch
{
   //do something here
}
like image 146
Andrew Lewis Avatar answered Oct 30 '22 22:10

Andrew Lewis