Here you go:
public class BaseClass
{
public void SomeMethod()
{
try
{
SomeOtherMethod();
}
catch(Exception ex)
{
Console.WriteLine("Caught Exception: " + ex.Message);
}
}
public virtual void SomeOtherMethod()
{
Console.WriteLine("I can be overridden");
}
}
public class ChildClass : BaseClass
{
public override void SomeOtherMethod()
{
throw new Exception("Oh no!");
}
}
SomeMethod, , SomeOtherMethod . SomeOtherMethod - , SomeMethod, . , , ( ChildClass, ), , , .
( , ) , , , ( ):
public class BaseClass
{
public void SomeMethod()
{
var thing = new ChildClass();
try
{
thing.ThrowMyException();
}
catch(Exception ex)
{
Console.WriteLine("Exception caught: " + ex.Message);
}
}
}
public class ChildClass : BaseClass
{
public void ThrowMyException()
{
throw new Exception("Oh no!");
}
}
, BaseClass.SomeMethod, , .