Exception Handling
 
Throw an Exception
 
The method instantiates an object of type Exception. The Exception constructor takes a String parameter. The string contains a message that can be retrieved when the exception is caught.
 
The throw statement terminates the method and gives its caller the opportunity to catch it:
 
if( correct > total )
{
throw new Exception( "Invalid values" ) ;
}
if ( (float)correct / (float)total > 0.70 )
{
returnCode = true ;
}
return returnCode ;
}