Home

How to catch unhandled exceptions in LINQPad.Controls onClick actions?

I've tried with this (Linqpad5):

void Main()
{
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

    //throw new Exception("Ex1");

    new LINQPad.Controls.Button("Fioo", (_) => {

        //insn't catched
        throw new Exception("Ex2");

    }).Dump();
}

void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
    var ex = (Exception)e.Exception;
    "Exception catched2".Dump();
}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    var ex = (Exception)e.ExceptionObject;
    "Exception catched1".Dump();
}

Comments

Sign In or Register to comment.