Browsing the network for better error handling in C #, I will talk about the following implementation strategies. The first is natural for me, but in another implementation I'm not sure what its advantages are?
1)
static void Fault(Action protectedBlock, Action faultHandler) { try { protectedBlock(); } catch { faultHandler(); throw; } }
2)
static Action Fault (Action protectedBlock, Action faultHandler) { return () => { try { protectedBlock (); } catch { faultHandler (); throw; } }; }
Is 2) the preferred strategy when developing higher order functions in C #?
And, I wonder if one approach is more effective than another.
Faultable Action Factory. , , protectedBlock , , Exception, faultHandler. , try/catch Action. , Exception , - , , .
protectedBlock
Exception
faultHandler
Action
2 , . , . , Action. , .
(2) , (1) . "", Action ( Func<A, R>).
Func<A, R>
, (2) :
Fault(someAction, Fault(firstTryFaultHandler, lastDitchFaultHandler))();
... . (1)
# 2 . "Fault (a, b)"; , , , b . , . , .
, 2 , "Fault (a, b)();", . .
1. , "() = > Fault (a, b)".
Source: https://habr.com/ru/post/1771733/More articles:Tweepy twitter oauth authentication does not return oauth_verifier - pythonphp and EOT constants - htmlUsing Maven as a build tool for Lua programs - luadrawLayer: inContext not called - iphoneВозможно ли unit test код, который не был первоначально спроектирован для тестирования, без изменения какого-либо кода? - language-agnosticHow can we determine the XElement value for CData? - xmlWhat is the fastest code to call multiple stored procedures? - c #Java - high processor performance - javaXML with embedded XSLT - xmlKornShell testing team (ksh) - unixAll Articles