Code Snippets from Work and Play Volume II

///Code Snippets from Work and Play Volume II

Welcome to Volume II of Code Snippets from Work and Play. See here for the first installment.
Let’s start with an improvement over our TryCatchMethod extension method:

TryCatchMethod with Func and “Continuation” Method

This overload is a Func with “continuation” Action and a couple other options.  Use it like this: Very handy and clean!

Update on Passing Parameters to TryCatchMethod

I commented in the last volume, that you could modify this to take parameters but with an action (duh), you simply need to call it like this (the continuation method and all options after the “this” are optional with defaults):

Reading the code, it may seem counter-intuitive that the action is still called, with the parameters, wrapped by the try/catch block. That’s the magic of anonymous/delegate and enclosure in C#. Thank you, Bjarne Stroustrup and team 🙂

By | 2017-11-17T11:30:35+00:00 May 9th, 2017|Categories: .NET, Development|Tags: , , |Comments Off on Code Snippets from Work and Play Volume II

About the Author:

Thanks for taking the time to read my profile and presumably my posts. I am a big city person living in a tiny town that offers no distracts from my passion: Creating software that helps others be more productive, happy, and enhances their work or personal life. I am a life-long learner, builder, writer, tinkerer, and when duty calls, an focused engineer and project manager.