Hi,
I've added a class to my application - I'm learning VB.NET as I go - and I'm wondering about the best way to handle errors and at what level should I be dealing with them at.
At the moment, I let the try / catch blocks handle any exceptions that may occur. But say if I have stuff like an XNameSpace as a property in a class and the parameter supplied to it turns out to be incorrect, which I wouldn't find out until calling:
I'm confused as to how I should handle errors of that sort (not the specific exception now just in general software terms). Should I check the validity of it in the constructor and throw an exception there or should I leave it up to the calling program to try/catch the exception?
Throwing an exception seems useful because if I was to return an error methods would have to be changed to constantly return an error type (an integer or something).
Any general tips or advice on error handling would be great, I'm currently reading through the Exception and Error Handling articles here: http://msdn.microsoft.com/en-us/library/s6da8809(VS.80).aspx but it's not really answering my question or I'm just not understanding the information.
Thanks,
Cossie
I've added a class to my application - I'm learning VB.NET as I go - and I'm wondering about the best way to handle errors and at what level should I be dealing with them at.
At the moment, I let the try / catch blocks handle any exceptions that may occur. But say if I have stuff like an XNameSpace as a property in a class and the parameter supplied to it turns out to be incorrect, which I wouldn't find out until calling:
VB.NET:
dim ns = XNameSpace.Get(nsURL)
Throwing an exception seems useful because if I was to return an error methods would have to be changed to constantly return an error type (an integer or something).
Any general tips or advice on error handling would be great, I'm currently reading through the Exception and Error Handling articles here: http://msdn.microsoft.com/en-us/library/s6da8809(VS.80).aspx but it's not really answering my question or I'm just not understanding the information.
Thanks,
Cossie
Last edited: