Creating a user defined Exception “FileFormatException” by extending IOException as following way
class FileFormatException extends IOException {
public FileFormatException ( ) { }
public FileFormatException ( String gripe ){
super (gripe);
}
}
And using that custom exception as follows:
String readData( BufferReader in ) throws FileFormatException {
…….
while ( ……) {
if ( ch = = -1) // EOF encountered
{
if ( n < len )
throw new FileFormatException ( ) ;
}
………
}
return s ;
}
i) What are the differences between throw and throws? ii) Analyze the above code and write down your comments on whether the procedure is correct ways to use exception or not.
i) Differences between throws and throw.
ii) The use of exception in the above code is correct because of the following reasons:
Comments
Leave a comment