-1

i am looking at

Is it correct that all (or in the most cases) the derived classes of System.Exception, whether user defined or system defined, are structurally equivalent to their base class System.Exception, despite of them being non nominally equivalent?

Thanks.

Tim
  • 1
  • 141
  • 372
  • 590
  • Perhaps you can share in your question why this is relevant and how you would like to use this information to structure exceptions in your code - example could work well. – Snympi May 22 '17 at 19:13

2 Answers2

1

No. When I inherit from System.Exception I add new variables to the derived class. Some stock exceptions do the same.

Joshua
  • 40,822
  • 8
  • 72
  • 132
1

Not Necessarily (and likely not at all). Any class that inherits off of System.Exception will, by definition, implement everything that System.Exception implements. However, it will also have its own differences.

Let's take a look at a simple example: ArgumentNullException. This is a System namespace exception, so was defined by the creators of C#. Comparing System.Exception to System.ArgumentNullException shows differences. For example:

ArgumentNullException has an additional constructor with the signature ArgumentNullException(String, String), allowing you to pass in the name of the parameter that is null.

ArgumentNullException has an additional Property: ParamName, used to hold the name of the parameter that is null and caused the exception.

Since I am just looking at the highest level, there are also likely differences in how the common methods between these are implemented.

Suffice it to say, a child class will very rarely look identical to its parent.

Marshall Tigerus
  • 3,675
  • 10
  • 37
  • 67