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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -