When i throw or catch any kind of an exception i would like to specify an error code along with it to be able to do something like the following:
Writeline(ex.Source + ex.Message + ex.Code);
can you show me a way or suggest something?
thank you all.
You have two choices:
1) If you are throwing your own exception, you can inherit from the exception class and add whatever properties you would like.
2) You can add name/value pairs to any Exception’s Data dictionary.
From the MSDN documentation, to add information to Data:
and to use that information: