try { // do something here } catch(Exception ex) { // will print System.NullReferenceException for example Console.WriteLine(ex.GetType().ToString()); }