java - How to create a checked exception and use it in the header of a method? -
for example:
int method1() throws new myexception { // here causes myexception's exception. }
i know should extend exception first. how trigger exception according method's state ?
i want able throw myexception whatever reason choose, similar how filenotfoundexception thrown when file isn't found.
minor correction required
int method1() throws exception { // based on validation logic throw new myexception(); }
update:- want handle file not found exception
int method1() throws exception { try { file handling code } catch(filenotfoundexception ex){ throw new myexception();// if want throw checked 1 otherwise below throw new runtimeexception();// unchecked ones } }
Comments
Post a Comment