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

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -