المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Need Help Understanding Error Handling



C# Programming
12-07-2010, 09:30 AM
I'm having trouble understanding, or rather some confussion with when to return error codes(User-Defined), true or false, when to throw an exception or handle as another path of logic. In some cases I may be making thing overly complex... I don't know.

For instance.. here is a code snippet where I'm I have a function that gets the correct WMI Namespace. If it returns a valid WMI Namespace, it continues on. In cases like this, is returning false the correct way to do this or should I be returning a user-defined error code? I understand the concept of the Try...Catch as well.. but it's what is supposed to be returned or thrown that makes me confused. http://www.barakasoft.com/script/Forums/Images/smiley_confused.gif


string correctNamespace = GetCorrectWmiNameSpace();
if (string.Equals(correctNamespace, string.Empty))
{
return false;
}