SHARE
TWEET

Untitled

a guest Jun 16th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private HttpResponseMessage TryCatch(Action action)
  2. {
  3.     return TryCatch(() => { action(); return "ActionToFunc"; });
  4. }
  5.  
  6. private HttpResponseMessage TryCatch<T>(Func<T> func)
  7. {
  8.     try
  9.     {
  10.         var result = func();
  11.  
  12.         if (result.ToString() == "ActionToFunc")
  13.         {
  14.             return Request.CreateResponse(HttpStatusCode.OK);
  15.         }
  16.  
  17.         return Request.CreateResponse(HttpStatusCode.OK, result);
  18.     }
  19.     catch (ArgumentNullException)
  20.     {
  21.         return Request.CreateResponse(HttpStatusCode.NotFound);
  22.     }
  23.     catch (Exception ex)
  24.     {
  25.         return Request.CreateResponse(HttpStatusCode.InternalServerError);
  26.     }
  27. }
  28.      
  29. TryCatch(() => myFunction(parameter));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top