In AutoCAD .NET API, we do run into cases from time to time where AutoCAD crashes even the code that causes the exception is wrapped in try...catch... block, but they usually happens with specific AutoCAD operation with abnormal situation, such as corrupted drawing file, or handling AutoCAD object in wrong way. It depends on how the .NET API wrapped the underline ObjectARX stuff.
But saying try...catch... does not catching array's IndexOutOfRange exception? I can only assume something very unusual with your code.
Here is simplified code to raise and handle array's IndexOutRange exception that works correctly, as expected:
using Autodesk.AutoCAD.Runtime;
using CadApp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: CommandClass(typeof(MiscTest.MyCommands))]
namespace MiscTest
{
public class MyCommands
{
[CommandMethod("CatchError1")]
public static void CatchErrorFromOutside()
{
var dwg = CadApp.DocumentManager.MdiActiveDocument;
var ed = dwg.Editor;
try
{
RaiseArrayOutOfRangeException();
}
catch (System.Exception ex)
{
CadApp.ShowAlertDialog($"Error caught from outside routine:\n{ex.Message}");
}
finally
{
Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
}
}
[CommandMethod("CatchError2")]
public static void CatchErrorFromInside()
{
var dwg = CadApp.DocumentManager.MdiActiveDocument;
var ed = dwg.Editor;
try
{
CatchArrayOutOfRangeExceptionFromInsideRoutine();
}
catch (System.Exception ex)
{
//This "catch..." clause should not be executed
CadApp.ShowAlertDialog($"Unhandled error from inside:\n{ex.Message}");
}
finally
{
Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
}
}
private static void RaiseArrayOutOfRangeException()
{
var numbers = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (int i=0; i<=20; i++)
{
//When i>9, an "Out of range" exception will be raised
string val = numbers[i].ToString();
}
}
private static void CatchArrayOutOfRangeExceptionFromInsideRoutine()
{
try
{
RaiseArrayOutOfRangeException();
}
catch (System.Exception ex)
{
CadApp.ShowAlertDialog($"Error caught from inside routine:\n{ex.Message}");
}
}
}
}
You may want to post your code to back up your claim.