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

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -