I am writing a custom .Net SDK for the mapping program MapInfo Pro, mapinfo only exposes two methods to use over COM void Do(string cmd)
and string Eval(string cmd)
. When you use one of these methods and you do something invaild, it returns a a COMException with a error message and I get the error code from MapInfo. So for example an error message looks like this:
418 "Table not found."
Now I would like to throw some kind of meaning full exception rather then just a exception with a number and message that people have to catch then use a if
block to check what error, something they say they only want to catch and do something meaning full with. Something like TableNotFoundException
.
The biggest problem is there are currently 1999
possible error messages, now I don't want a exception class for everyone of those errors.
The idea of the SDK is that people use my objects and methods rather then Do
and Eval
(they can stil use them if they want).
Should I,
- everywhere in my SDK that I call
Do
andEval
use a try catch and then check the error code and throw something more meaning full from there, because I know what errors I should get.
or
- I have somekind of God lookup list in the
Do
andEval
that when aCOMException
is thrown it lookups the error code and throws the meaningfull error from there? Meaning I don't have to wrap every call toDo
andEval
in try catch blocks(there are a lot of calls)
Bit of a tricky thing to explain so I hope people can understand it.
Thanks.