java - Making an exception class and leaving it empty -
now i've created exception class haven't created constructor shown
public class invalidchoiceexception extends exception { }
but catch block handles want display.
try { if(readfile.hasnextint() == false) throw new inputmismatchexception(); else { num = readfile.nextint(); readfile.nextline(); } } catch (inputmismatchexception e) { system.err.println("integer expected"); e.printstacktrace(); system.exit(0); }
is ok do?
edit: let's pretend input mismatch empty exception class though it's not..
creating empty subclass of exception allowed. catch not able tag instance error message or cause (these standard piece of information associated exception).
however if use case doesn't require specify messages or causes of exceptions such design.
Comments
Post a Comment