0

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

brumScouse
  • 3,166
  • 1
  • 24
  • 38

2 Answers2

0

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
  • 11,878
  • 2
  • 35
  • 51
  • 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 Oct 06 '10 at 20:03
  • 1
    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 Oct 06 '10 at 20:10
0

I have recently had a bit more of a detailed looked at application blocks. Perhaps using the exception or policy injection application blocks might have some legs.

brumScouse
  • 3,166
  • 1
  • 24
  • 38