Author Topic: UnhandledException event doesn't happen  (Read 2760 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
UnhandledException event doesn't happen
« on: December 22, 2010, 08:46:10 AM »
Windows XP SP3 x86 Rus
AutoCAD 2009 SP3 x86 Enu
.Net Framework 3.5 SP1
MS VS 2010
Code: [Select]
...
AppDomain.CurrentDomain.UnhandledException+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
//Test
int ggg = 4;
int fff = 5 / (4 - ggg);//Error generate.
...

        void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
            if (Drawing != null) Drawing.Editor.WriteMessage(string.Format("\n{0}: {1}\n", Resource.ErrorMessage, ((System.Exception)e.ExceptionObject).Message));
            if (XmlCommonSettings != null) SendErrorMail(Resource.UnhandledException, (System.Exception) e.ExceptionObject);
        }

But after an error there is no event UnhandledException. How it is possible to solve this problem?

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: UnhandledException event doesn't happen
« Reply #1 on: January 19, 2011, 05:20:18 AM »
up

Jeff H

  • Needs a day job
  • Posts: 6150
Re: UnhandledException event doesn't happen
« Reply #2 on: January 19, 2011, 05:35:10 AM »
Have you tried putting it in a try catch block?

And using the DivideByZeroException class?




Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                int ggg = 4;
                int fff = 5 / (4 - ggg);//Error generate.\
            }
            catch (DivideByZeroException e)
            {
                // Do what you want
                MessageBox.Show(e.Message);
            }

        }       
    }
}



Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: UnhandledException event doesn't happen
« Reply #3 on: January 19, 2011, 06:10:18 AM »
>Jeff H
I must get mail with error information, when unhandled exception occur on user's computer.

In my code (look my first post) the error is generated intentionally to cause event UnhandledException. But the specified event doesn't come (in AutoCAD plugins). Why UnhandledException not happend?

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: UnhandledException event doesn't happen
« Reply #4 on: January 19, 2011, 06:20:10 AM »
Real code screen:



In line 128 I register event UnhandledException.
In line 149 I generate an exception but after that I don't get to a line 160 because AutoCAD completes plug-in operation.

It is necessary for me, that the code from a line 160 was fulfilled in the presence of a raw exception.

Glenn R

  • Guest
Re: UnhandledException event doesn't happen
« Reply #5 on: January 19, 2011, 10:11:04 AM »
This will not catch anything and AutoCAD does not fail:

Code: [Select]
void IExtensionApplication.Initialize()
{
      throw new DivideByZeroException();
 }

This will catch the exception:

Code: [Select]
void IExtensionApplication.Initialize()
{
    try
    {
        throw new DivideByZeroException();
    }
    catch (DivideByZeroException ex)
    {
        acadApp.ShowAlertDialog(ex.ToString());
    }
}

When AutoCAD calls Initialize(), it must wrap it in an try/catch block and swallow the exception.