//------------------------------------------------------------------------- public virtual void test_consumer_success() { System.Action <string> a = Unchecked.consumer((t) => { }); a("A"); }
public virtual void test_consumer_fail2() { System.Action <string> a = Unchecked.consumer((t) => { throw new Exception(); }); assertThrows(() => a("A"), typeof(Exception)); }
//------------------------------------------------------------------------- /// <summary> /// Converts checked exceptions to unchecked based on the {@code Consumer} interface. /// <para> /// This wraps the specified consumer returning an instance that handles checked exceptions. /// If a checked exception is thrown it is converted to an <seealso cref="UncheckedIOException"/> /// or <seealso cref="RuntimeException"/> as appropriate. /// /// </para> /// </summary> /// @param <T> the type of the consumer </param> /// <param name="consumer"> the consumer to be decorated </param> /// <returns> the consumer instance that handles checked exceptions </returns> public static System.Action <T> consumer <T>(CheckedConsumer <T> consumer) { return((t) => { try { Unchecked.consumer(t); } catch (Exception ex) { throw propagate(ex); } }); }