Hi there,
I had been wondering for a while. I am building a very efficient Custom Exception Library. But i wasn't that sure whether i should be using XML or not.
There are 3 ways which i thought off.
1) The tradional way, how my office people handles exception in C language.
Exceptions are stored in enum
typedef enum
{
ERR_PORTDEAD = -50,
ERR_ONHOLD,
OK = 0
} STATUSERROR;
They do validations by;
if (CheckStatusPort(portNumber))
return ERR_PORTDEAD;
once detect to the client side, you had to manually concanenate the error message with a description. Troublesome.
I don't like this way.
2) So yesterday, i think of pushing my exceptions messages and stored into hashtable.
Example,
Key = -50
Value = "Error Port Dead"
Hashtable table = new Hasthtable();
table.Add(-50, "Error Port Dead");
Just keep on adding.
Once i want to do this;
If (CheckStatusReport(portNumber))
throw new CustomeException(table[-50]);
So at the end it throws out everything.
3) But the problem, is all the codes need to be manually written in C#.
Is there a way? XML or Text File. Whatever.
<xml>
<Error>
<Type>Port</Type>
<ID>-50</ID>
<Desc>Port is dead</Desc>
<Solution>Additional - cool!</Solution>
</Error>
</xml>
Somehow you will load this inside the class library,
throw new Exception((get_from_the_xml_file_with_key_-50));
What do you think?
At least in future, they can change the xml file without recompiling.
At the end of the day, i need to achieve a better, efficient of way of error handling.
Of course i am building a custom exception class that inherits from System.ApplicationException.
Can anyone shed their personal comments please based on their experiences?
Thanks.
--
Regards,
Chua Wen Ching :)