开发者

How would I implicitly call a method after having explicitly called another specific type of method

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 thin开发者_StackOverflow社区king 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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜