AsDoesntThrow

public static Action AsDoesntThrow<T>(this Action action)
            where T : Exception
{
    return (() =>
        {
            try
            {
                action();
            }
            catch (T) {}
        });
}
Example:
var thisActionThrows = () => { throw new NullReferenceException() };
var thisDoesntThrow = thisActionThrows.AsDoesntThrow<NullReferenceException>();

Description

Wraps an action with a try...catch of a specific exception

Details

  • Author: ytoledano
  • Submitted on: 3/2/2013 2:09:59 PM
  • Language: C#
  • Type: Action
  • Views: 2010

Double click on the code to select all.

 

;