Declare an exception to be thrown as shown below:
public void someMethod() throws Exception { if(somethingBad) { throw new Exception(); } } Catch an exception as shown below:
public void someMethod() { // code for an operation that could cause an exception... try { // ...some code } catch(Exception e) { // exception handling code here } finally { // this code executes whether an exception was // thrown or not } } | |
| Top |