ToException

public static void ToException<T>(this string message) where T : Exception, new()
{
      var e = (T)Activator.CreateInstance(typeof(T), message);
      throw e;
}
Example:
"ferhat".ToException<FileNotFoundException>();
"ferhat".ToException<Exception>();
"ferhat".ToException<IOException>();

Description

String Typed Exception Extension

Details

Double click on the code to select all.

 

;