Ejemplo n.º 1
0
 /// <summary>
 /// Do an action within an exception guard
 /// </summary>
 /// <param name="action">The action to execute</param>
 /// <returns></returns>
 public static void Do(Action action)
 {
     try
     {
         action.Invoke();
     }
     catch (ShocException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new ShocException(new List <ErrorDefinition> {
             ErrorDefinition.Unknown(e.Message)
         }, e.Message, e);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Do an operation within an exception guard async
 /// </summary>
 /// <typeparam name="T">The result type</typeparam>
 /// <param name="supplier">The supplier to execute</param>
 /// <returns></returns>
 public static async Task <T> DoAsync <T>(Func <Task <T> > supplier)
 {
     try
     {
         return(await supplier.Invoke());
     }
     catch (ShocException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new ShocException(new List <ErrorDefinition> {
             ErrorDefinition.Unknown(e.Message)
         }, e.Message, e);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates new instance for error definition
 /// </summary>
 public ShocException(string message) : this(new List <ErrorDefinition> {
     ErrorDefinition.Unknown(message)
 }, message)
 {
 }