Java Reference
In-Depth Information
exceptionmustbethrown.Furthermore,thisexceptionmuststoretheexpectedandex-
istingmediaformatssothatahandlercanidentifythemwhenpresentingamessageto
the user.
Because Java's class library does not provide a suitable exception class, you decide
tointroduceaclassnamed InvalidMediaFormatException .Detectinganinval-
idmediaformatisnottheresultofacodingmistake,andsoyoualsodecidetoextend
Exception toindicatethattheexceptionischecked. Listing3-24 presentsthisclass's
declaration.
Listing 3-24. Declaring a custom exception class
package media;
public class InvalidMediaFormatException extends Exception
{
private String expectedFormat;
private String existingFormat;
public
InvalidMediaFormatException(String
expec-
tedFormat,
String
existin-
gFormat)
{
super("Expected format: "+expectedFormat+", Existing
format: "+
existingFormat);
this.expectedFormat = expectedFormat;
this.existingFormat = existingFormat;
}
public String getExpectedFormat()
{
return expectedFormat;
}
public String getExistingFormat()
{
return existingFormat;
}
}
Search WWH ::




Custom Search