Java Reference
In-Depth Information
Listing 3-26. Handling different kinds of exceptions
import java.io.FileNotFoundException;
import java.io.IOException;
import media.InvalidMediaFormatException;
import media.Media;
class Converter
{
public static void main(String[] args)
{
if (args.length != 2)
{
System.err.println("usage: java Converter srcfile
dstfile");
return;
}
try
{
Media.convert(args[0], args[1]);
}
catch (InvalidMediaFormatException imfe)
{
System.out.println("Unable to convert "+args[0]+"
to "+args[1]);
System.out.println("Expecting "+args[0]+" to con-
form to "+
imfe.getExpectedFormat()+"
format.");
System.out.println("However,
"+args[0]+"
con-
formed to "+
imfe.getExistingFormat()+"
format.");
}
catch (FileNotFoundException fnfe)
{
Search WWH ::




Custom Search