I have a wrapper which interacts with a third party component. In Each function i am performing the operation if it the component is initialized.
I have other function to check the errorCode and component initialization check.
Is this right way to do this? I am not happy with the readability of this code. Help me improving this code.
Thanks in advance.
Void Operation1 (parameter someInput)
{
int errorCode= 0;
if (Initialized)
{
errorCode = ThirdPartyComponent.Operation1(someInput);
}
CheckErrorCodeAndShowError ("Operation1 with someInput failed", returnValue);
}
Void Operation2 (parameter someInput)
{
int errorCode= 0;
if (Initialized)
{
errorCode = ThirdPartyComponent.Operation2(someInput);
}
CheckErrorCodeAndShowError ("Operation2 with someInput failed", returnValue);
}
Void CheckErrorCodeAndShowError (String errorMessage, int errorCode)
{
if (!Initialized)
{
//Show not initialized error
}
if (errorCode == -1)
{
//Show Operation failed error (errorMessage)
}
else if (errorCode == 0)
{
//Show operation success message etc
}
//other error code check
}
-1
when there is an error? Does it not have any way to get some extended information. Like a Windows "GetLastError" type of call? – pstrjds Jan 3 '13 at 7:44