< Java Programming < Keywords
throw
is a keyword; it 'throws' an exception. In a throw statement, the three types of objects that can be thrown are: Exception, java:Throwable, and java:Error
Syntax:
throw
<Exception Ref>;
For example:
![]() |
public Customer findCustomer( String name ) throws '''CustomerNotFoundException'''
{
Customer custRet = null;
Iterator iter = _customerList.iterator();
while ( iter.hasNext() )
{
Customer cust = (Customer) iter.next();
if ( cust.getName().equals( name ) )
{
// --- Customer find --
custRet = cust;
break;
}
}
if ( custRet == null )
{
// --- Customer not found ---
throw new '''CustomerNotFoundException'''( "Customer "+ name + " was not found" );
}
return custRet
}
|
See also
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.