In ObjectARX, there is acedDisableDefaultARXExceptionHandler function. You can try P / Invoke it.
// EntryPoint may vary across autocad versions [DllImport("acad.exe", EntryPoint = " ?acedDisableDefaultARXExceptionHandler@ @ YAXH@Z ")] public static extern void acedDisableDefaultARXExceptionHandler(int value);
You can also try System.Windows.Forms.Application.ThreadException: http://through-the-interface.typepad.com/through_the_interface/2008/08/catching-except.html
The easiest way to do this is to wrap all your code in a try / catch block. There are two ways to execute code in AutoCAD:
Using command
To avoid code duplication, declare the interface as follows:
public interface ICommand { void Execute(); }
Then use it for your command:
public class MyCommand : ICommand { void Execute() {
In the class where your commands are defined, use this general method to execute:
void ExecuteCommand<T>() where T : ICommand { try { var cmd = Activator.CreateInstance<T>(); cmd.Execute(); } catch (Exception ex) { Log(ex); } }
Now your command looks like this:
[CommandMethod("MYCMD", CommandFlags.Modal)] public void MyCommand() { ExecuteCommand<MyCommand>(); }
In the event handler
In this case, since you need the event arguments, just wrap your code directly in try / catch.
source share