code_junkie

Calling base constructor in c#

Nov 10th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. class MyExceptionClass : Exception
  2. {
  3. public MyExceptionClass(string message, string extraInfo)
  4. {
  5. //This is where it's all falling apart
  6. base(message);
  7. }
  8. }
  9.  
  10. public class MyExceptionClass : Exception
  11. {
  12. public MyExceptionClass(string message, string extrainfo) : base(message)
  13. {
  14. //other stuff here
  15. }
  16. }
  17.  
  18. class MyExceptionClass : Exception
  19. {
  20. public MyExceptionClass(string message, string extraInfo) :
  21. base(ModifyMessage(message, extraInfo))
  22. {
  23. }
  24.  
  25. private string ModifyMessage(string message, string extraInfo)
  26. {
  27. Trace.WriteLine("message was " + message);
  28. return message.ToLowerInvariant() + Environment.NewLine + extraInfo;
  29. }
  30. }
  31.  
  32. // Constructor 1
  33. public MyExceptionClass(string message, string extraInfo) :
  34. this(17) // calls constructor 2
  35. {
  36. // ...
  37. }
  38.  
  39. // Constructor 2
  40. public MyExceptionClass(int foo)
  41. {
  42. // ...
  43. }
  44.  
  45. public class MyExceptionClass : Exception
  46. {
  47. public MyExceptionClass(string message,
  48. Exception innerException): base(message, innerException)
  49. {
  50. //other stuff here
  51. }
  52. }
Add Comment
Please, Sign In to add comment