123
Way 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MySpecialException { class Program { static void Main(string[] args) { try { SomeClass sc = new SomeClass(); sc.SomeMethod(); } catch (SomeSpecialException e) { Console.WriteLine( e.Message+"\n\r"+ e.ErrorTimeStamp+ "\n\r"+ e.CauseOfError+ "\n\r" ); Console.ReadLine(); } } } public class SomeClass { public void SomeMethod() { //code SomeSpecialException ex = new SomeSpecialException("123","123",DateTime.Now); ex.HelpLink = "someLink"; throw ex; //code } } //--- public class SomeSpecialException : ApplicationException { private string MessageDetails = String.Empty; public DateTime ErrorTimeStamp { get; set; } public string CauseOfError { get; set; } //... public SomeSpecialException(string message,string cause, DateTime time) { MessageDetails = message; ErrorTimeStamp = time; CauseOfError = cause; } //overriding Message Property public override string Message { get { return string.Format("ErrorMessage:{0}", MessageDetails); } } } } |