exception - super statement in C# -
i'm creating class manage exception in c#, , i'd create constructor methods recalls superclass; definition of class:
class datasourcenotfoundexception: system.exception
but since in c# there no super method supposed call constructor methods of system.exception
?
you call parent constructor using base
before body of constructor:
public class fooexception : exception { public fooexception(string message) : base(message) { } }
obviously don't have pass parameter own constructor argument base constructor:
public class fooexception : exception { public fooexception(int x) : base("hello") { // x } }
the equivalent chain constructor in current class use this
instead of base
.
note constructor chaining works very differently in c# compared java, respect when instance variable initializers run. see article on c# constructors more details.
Comments
Post a Comment