Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
1.1
-
None
-
None
Description
In inheritance tree of exceptions each exception has its GetMessage() method marked as 'new' which disables user from using polymorphism when having ancestor instance of ancestor exception cast to base type. Wouldn't it be better to use virtual GetMessage method on the base class and then have it overridden in ancestors?
example:
public class BaseException
{
public virtual string GetMessage()
//currently
//public string GetMessage()
}
public class InheritedException : BaseException
{
public override string GetMessage() { return "Inhertied exception message";}
//currently hiding the method from base class
//public new string GetMessage(){...}
}
so then
((new InheritedException())as BaseException).GetMessage(); //would return "Inherited exception message"