java - How to inherit a RuntimeException class? -
i have 2 options:
public class syntaxexception extends runtimeexception { private string msg; public syntaxexception(string m) { this.msg = m; } public string getmessage() { return "invalid syntax: " + this.msg; } } and
public class syntaxexception extends runtimeexception { public syntaxexception(string m) { super("invalid syntax: " + m); } } which 1 preferred, if have think code maintainability , extendability?
use second one. argument constructor of both runtimeexception , inherited class error message, there's no reason duplicate functionality given runtimeexception in code.
Comments
Post a Comment