views:

14

answers:

1

Lets say I have a bunch of methods in a class which call a Webservice and, as a result, I need to check the "response" of the Webservice each time one of these methods is called.
But I don't want to do something like this:

MethodA() // non web service related method

MethodB() // Web service calling method

if _response == OK then 
   MethodC()

In essence I want to get the check without explicitly calling it.

So I would actually like to be doing something like this:

MethodA()
MethodB() //If this fails, don't continue 
MethodC() 

And I would bomb out of the calling sequence with the internal _response variable updated and execution stopping.

As I am typing I am thinking that each of the Methods would need to do the check themselves or at least call something which does this check before doing their thang.

Am I overcomplicating things here?

Thanks

A: 

Throw an exception in MethodB() and handle it in upper level. This way, if exception is thrown inside MethodB(), MethodC() won't get called.

Victor Sorokin
I was kind of hoping for something a little less heavyweight and elegant than using exceptions. AFAIK Exception handling shouldn't be used to control the flow of a program.
brumScouse
I can only direct you to http://stackoverflow.com/questions/253314/exceptions-or-error-codes, there's lot of discussion on this topic.
Victor Sorokin
nice one for the info :)
brumScouse