| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System;
- namespace Quadarax.Foundation.Core.Exceptions
- {
- public static class TryCatchExt
- {
- public static Exception? TryCatch<TResult>(this object owner, Func<TResult>? fnc)
- {
- if (owner == null)
- throw new ArgumentNullException(nameof(owner));
- if (fnc == null)
- return null;
- try
- {
- fnc();
- }
- catch (Exception e)
- {
- return e;
- }
- return null;
- }
- public static Exception? TryCatch(this object owner, Action? fnc)
- {
- if (owner == null)
- throw new ArgumentNullException(nameof(owner));
- if (fnc == null)
- return null;
- try
- {
- fnc();
- }
- catch (Exception e)
- {
- return e;
- }
- return null;
- }
- }
- }
|