1717#region U S A G E S
1818
1919using System ;
20- using System . Diagnostics ;
2120using TryToExecute . Extensions ;
2221using TryToExecute . Helpers ;
2322
@@ -54,31 +53,8 @@ protected virtual TResult TryToExecute<TResult>(
5453 TResult onFailureResult ,
5554 Action finallyExecAction ,
5655 bool forceCallGarbageCollector = false )
57- {
58- try
59- {
60- return execRequest ;
61- }
62- catch ( Exception e )
63- {
64- #if DEBUG
65- Debug . WriteLine ( e ) ;
66- #if NETSTANDARD1_3_OR_GREATER
67- Console . WriteLine ( e ) ;
68- #endif
69- #endif
70-
71- return onFailureResult ;
72- }
73- finally
74- {
75- if ( finallyExecAction . IsNotNull ( ) )
76- finallyExecAction ? . Invoke ( ) ;
77-
78- if ( forceCallGarbageCollector . IsTrue ( ) )
79- TryToExecuteAppHelper . ForceCallGC ( ) ;
80- }
81- }
56+ => InternalTryCatchExecHelper . TryIt < TResult , TResult , TResult , Action > (
57+ execRequest , onFailureResult , finallyExecAction , forceCallGarbageCollector ) ;
8258
8359 /// -------------------------------------------------------------------------------------------------
8460 /// <summary>
@@ -103,29 +79,8 @@ protected virtual TResult TryToExecute<TResult>(
10379 {
10480 execFunc . ThrowIfArgNull ( nameof ( execFunc ) ) ;
10581
106- try
107- {
108- return execFunc . Invoke ( ) ;
109- }
110- catch ( Exception e )
111- {
112- #if DEBUG
113- Debug . WriteLine ( e ) ;
114- #if NETSTANDARD1_3_OR_GREATER
115- Console . WriteLine ( e ) ;
116- #endif
117- #endif
118-
119- return onFailureResult ;
120- }
121- finally
122- {
123- if ( finallyExecAction . IsNotNull ( ) )
124- finallyExecAction ? . Invoke ( ) ;
125-
126- if ( forceCallGarbageCollector . IsTrue ( ) )
127- TryToExecuteAppHelper . ForceCallGC ( ) ;
128- }
82+ return InternalTryCatchExecHelper . TryIt < TResult , Func < TResult > , TResult , Action > (
83+ execFunc , onFailureResult , finallyExecAction , forceCallGarbageCollector ) ;
12984 }
13085
13186#if NETSTANDARD2_0_OR_GREATER
@@ -156,30 +111,8 @@ protected virtual TResult TryToExecute<TResult, TLogger>(
156111 execFunc . ThrowIfArgNull ( nameof ( execFunc ) ) ;
157112 exceptionLogger . ThrowIfArgNull ( nameof ( exceptionLogger ) ) ;
158113
159- try
160- {
161- return execFunc . Invoke ( ) ;
162- }
163- catch ( Exception e )
164- {
165- #if DEBUG
166- Debug . WriteLine ( e ) ;
167- #if NETSTANDARD1_3_OR_GREATER
168- Console . WriteLine ( e ) ;
169- #endif
170- #endif
171- exceptionLogger . LogError ( e , DefaultMessageHelper . InternalErrorOnTryExecute ) ;
172-
173- return onFailureResult ;
174- }
175- finally
176- {
177- if ( finallyExecAction . IsNotNull ( ) )
178- finallyExecAction ? . Invoke ( ) ;
179-
180- if ( forceCallGarbageCollector . IsTrue ( ) )
181- TryToExecuteAppHelper . ForceCallGC ( ) ;
182- }
114+ return InternalTryCatchExecHelper . TryIt < TResult , Func < TResult > , TResult , Action , TLogger > (
115+ execFunc , onFailureResult , finallyExecAction , exceptionLogger , forceCallGarbageCollector ) ;
183116 }
184117#endif
185118
@@ -207,29 +140,8 @@ protected virtual TResult TryToExecute<TResult>(
207140 execFunc . ThrowIfArgNull ( nameof ( execFunc ) ) ;
208141 onFailureResult . ThrowIfArgNull ( nameof ( onFailureResult ) ) ;
209142
210- try
211- {
212- return execFunc . Invoke ( ) ;
213- }
214- catch ( Exception e )
215- {
216- #if DEBUG
217- Debug . WriteLine ( e ) ;
218- #if NETSTANDARD1_3_OR_GREATER
219- Console . WriteLine ( e ) ;
220- #endif
221- #endif
222-
223- return onFailureResult . Invoke ( ) ;
224- }
225- finally
226- {
227- if ( finallyExecAction . IsNotNull ( ) )
228- finallyExecAction ? . Invoke ( ) ;
229-
230- if ( forceCallGarbageCollector . IsTrue ( ) )
231- TryToExecuteAppHelper . ForceCallGC ( ) ;
232- }
143+ return InternalTryCatchExecHelper . TryIt < TResult , Func < TResult > , Func < TResult > , Action > (
144+ execFunc , onFailureResult , finallyExecAction , forceCallGarbageCollector ) ;
233145 }
234146
235147 /// -------------------------------------------------------------------------------------------------
@@ -256,29 +168,8 @@ protected virtual TResult TryToExecute<TResult>(
256168 execFunc . ThrowIfArgNull ( nameof ( execFunc ) ) ;
257169 onFailureResult . ThrowIfArgNull ( nameof ( onFailureResult ) ) ;
258170
259- try
260- {
261- return execFunc . Invoke ( ) ;
262- }
263- catch ( Exception e )
264- {
265- #if DEBUG
266- Debug . WriteLine ( e ) ;
267- #if NETSTANDARD1_3_OR_GREATER
268- Console . WriteLine ( e ) ;
269- #endif
270- #endif
271-
272- return onFailureResult . Invoke ( e ) ;
273- }
274- finally
275- {
276- if ( finallyExecAction . IsNotNull ( ) )
277- finallyExecAction ? . Invoke ( ) ;
278-
279- if ( forceCallGarbageCollector . IsTrue ( ) )
280- TryToExecuteAppHelper . ForceCallGC ( ) ;
281- }
171+ return InternalTryCatchExecHelper . TryIt < TResult , Func < TResult > , Func < Exception , TResult > , Action > (
172+ execFunc , onFailureResult , finallyExecAction , forceCallGarbageCollector ) ;
282173 }
283174
284175#if NETSTANDARD2_0_OR_GREATER
@@ -310,30 +201,8 @@ protected virtual TResult TryToExecute<TResult, TLogger>(
310201 onFailureResult . ThrowIfArgNull ( nameof ( onFailureResult ) ) ;
311202 exceptionLogger . ThrowIfArgNull ( nameof ( exceptionLogger ) ) ;
312203
313- try
314- {
315- return execFunc . Invoke ( ) ;
316- }
317- catch ( Exception e )
318- {
319- #if DEBUG
320- Debug . WriteLine ( e ) ;
321- #if NETSTANDARD1_3_OR_GREATER
322- Console . WriteLine ( e ) ;
323- #endif
324- #endif
325- exceptionLogger . LogError ( e , DefaultMessageHelper . InternalErrorOnTryExecute ) ;
326-
327- return onFailureResult . Invoke ( ) ;
328- }
329- finally
330- {
331- if ( finallyExecAction . IsNotNull ( ) )
332- finallyExecAction ? . Invoke ( ) ;
333-
334- if ( forceCallGarbageCollector . IsTrue ( ) )
335- TryToExecuteAppHelper . ForceCallGC ( ) ;
336- }
204+ return InternalTryCatchExecHelper . TryIt < TResult , Func < TResult > , Func < TResult > , Action , TLogger > (
205+ execFunc , onFailureResult , finallyExecAction , exceptionLogger , forceCallGarbageCollector ) ;
337206 }
338207#endif
339208
@@ -366,30 +235,8 @@ protected virtual TResult TryToExecute<TResult, TLogger>(
366235 onFailureResult . ThrowIfArgNull ( nameof ( onFailureResult ) ) ;
367236 exceptionLogger . ThrowIfArgNull ( nameof ( exceptionLogger ) ) ;
368237
369- try
370- {
371- return execFunc . Invoke ( ) ;
372- }
373- catch ( Exception e )
374- {
375- #if DEBUG
376- Debug . WriteLine ( e ) ;
377- #if NETSTANDARD1_3_OR_GREATER
378- Console . WriteLine ( e ) ;
379- #endif
380- #endif
381- exceptionLogger . LogError ( e , DefaultMessageHelper . InternalErrorOnTryExecute ) ;
382-
383- return onFailureResult . Invoke ( e ) ;
384- }
385- finally
386- {
387- if ( finallyExecAction . IsNotNull ( ) )
388- finallyExecAction ? . Invoke ( ) ;
389-
390- if ( forceCallGarbageCollector . IsTrue ( ) )
391- TryToExecuteAppHelper . ForceCallGC ( ) ;
392- }
238+ return InternalTryCatchExecHelper . TryIt < TResult , Func < TResult > , Func < Exception , TResult > , Action , TLogger > (
239+ execFunc , onFailureResult , finallyExecAction , exceptionLogger , forceCallGarbageCollector ) ;
393240 }
394241#endif
395242 }
0 commit comments