Hi all,
I recently came across DotNet samples of Map 3d 2011.
I’m talking about Topology samples.
How I can catch errors code of Map with error message correctly in Dot.NET?
In autolisp I make with functions for handling error messages begin with ade_err:
ade_errmsg, ade_errcode ....
Dot.Net:
try
{
// Do something……………………..
}
catch(MapException ex)
{
Utility.AcadEditor.WriteMessage("\nERROR: --------");
}
MapException not represented error message correctly.
Thanks!
MapException has properties like Message, InnerException, ErrorCode...
When handling exception, if you only want to show error message, you can
try
{
...
}
catch(MapException ex)
{
theEditor.WriteMessage("\nERROR: " + ex.Message)
}
You need to be aware, in many cases, the Exception thrown by AutoCAD Map is an exception object that is derived from MapException, such as MapImportExportException. Sometimes you want to go down into the InnerException:
theEditor.WriteMessage("\nError: " + e.InnerException.Message)
It all depends on what the operation the code is doing and what possible type of exception the code could be raising... You may want to use multiple catch{} clause to catch different type of exception and handle them accordingly, fromo the most concrete type to most generic type. For example, in your very complicated Importing/Exporting process:
try
{
...
}
catch(MapImortExportException imexEx)
{
...
}
catch(MapException mex)
{
...
}
catch(Autodesk,AutoCAD.Runtime.Exception aex)
{
..
}
catch(System.Exception ex)
{
//handle all other exceptiones other than the 3 exceptions being caugth in above catch{} clauses
...
}
Of course, if you do not embed huge, complicated process in the try{} block, you may not need that complicated multiple catch{}
Norman Yuan