Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private HttpResponseMessage TryCatch(Action action)
- {
- return TryCatch(() => { action(); return "ActionToFunc"; });
- }
- private HttpResponseMessage TryCatch<T>(Func<T> func)
- {
- try
- {
- var result = func();
- if (result.ToString() == "ActionToFunc")
- {
- return Request.CreateResponse(HttpStatusCode.OK);
- }
- return Request.CreateResponse(HttpStatusCode.OK, result);
- }
- catch (ArgumentNullException)
- {
- return Request.CreateResponse(HttpStatusCode.NotFound);
- }
- catch (Exception ex)
- {
- return Request.CreateResponse(HttpStatusCode.InternalServerError);
- }
- }
- TryCatch(() => myFunction(parameter));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement