I have two 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 one is preferable if I need to think about code support and extensibility?
Use the second one. The argument to the constructor of both RuntimeExceptionyou and your inherited class is the error message, so there is no reason to duplicate this functionality already specified RuntimeExceptionin your code.
RuntimeException
Im going with number 2. Number one looks like reinventing the wheel.
, YAGNI KISS, , getMessage() msg . , - , , " / ".
getMessage()
msg
getMessage(), .
.
" :" , :
public class SyntaxException extends RuntimeException { public SyntaxException(String wrongSyntax) { super("Invalid syntax: " + wrongSyntax); } }
, i18n .
. , .
Source: https://habr.com/ru/post/1775216/More articles:How to save temporary files on request in Rails? - ruby-on-railsCSS: Can I choose a specific child plus the next next brother? - csshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1775213/is-there-a-warning-free-template-function-to-convert-basic-types-to-string&usg=ALkJrhhmMRqywhJM-Vm8YaxZajnc0Y0m8QLog4j java.lang.NoClassDefFoundError - javaHow to get only the visible part of the window (Windows, gdi32, user32, etc.) - javaFinding the frame rate on a custom Java component correctly - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1775218/is-there-a-possibility-to-assign-cssclass-to-checkbox-within-checkboxlist&usg=ALkJrhiEs578stzLqW4fhCfUn503_Q5BDgPrevent order confirmations sent via PHPMailer as a result of spam - phpИспользование Содержит в ObjectQuery - c#SQL Server Question - XML query - sqlAll Articles