Creating exception classes for different error codes

I am writing a custom .Net SDK for the MapInfo Pro mapping program, mapinfo provides only two methods for use through 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 COMException with an error message, and I get the error code from MapInfo. So, for example, the error message is as follows:

 418  "Table not found."

Now I would like to add some kind of total exception value, not just an exception with a number and a message that people should catch, and then use the block ifto check what kind of error, something that they say they only want to catch and do something that means complete. Something like that TableNotFoundException.

The biggest problem is that there are currently 1999possible error messages, now I don’t need an exception class for all these errors.

The idea of ​​the SDK is that people use my objects and methods, not Doand Eval(they can use them if they want).

Should I,

  • everywhere in my SDK that I call Doand Evaluse try catch and then check the error code and throw something more out of there because I know what errors I should get.

or

  • I have a list of people search in Doand Evalwhich, when thrown COMException, it searches for an error code and gives a significant error from it? Meaning: I do not need to wrap every call Doand Evalin the units try catch (there's a lot of calls)

, , .

.

+3
2

Do Eval , MapInfo.

, ( ) - 1999 , , . , Do Eval , , . .

, ( - 0-1999 = > ). , , .

+3

AndiDog, , . , , , , .

, , , , , , DON ' T .

0

Source: https://habr.com/ru/post/1733308/


All Articles