Hello!
I have this small class CustomException with one ctor see below.
In this class I have both override the ToString and Message.
Now to my question if I made this call
string ss = ToString(); in the ctor for this class CustomException
I call the overridden ToString in this class CustomException.
If I made this call string sss = base.ToString();
in the ctor for this class CustomException I also call the overridden
ToString in this class CustomException
Now can somebody explain why second example will call the ToString in my
class CustomException
If I write little pseudocode I can understand it if we had this
construction.
I just use base as an instance variable of CustomException
Exception base = new CustomException()
base.ToString();
because here the dynamic type is CustomException and we will have polymorf
call so ToString in class CustomException will be called.
But when we have string sss = base.ToString();
what is the dynamic type for base?
public class CustomException : Exception
{
private MathClass mathobject;
private string sMessage;
public CustomException(string sMsg, MathClass mo)
{
mathobject = mo;
sMessage = sMsg;
//string ss = ToString();
//string sss = base.ToString();
}
override public string Message
{
get{return String.Format("Message is <{0}>, Object is {1}",
sMessage, mathobject.ToString());}
}
override public string ToString()
{
string s = Message;
s += "\nException thrown from ";
s += TargetSite;
return s;
}
}
//Tony