All exceptions other than RuntimeException and Error must be caught or the Java code will not compile.

try
{
    :
    in = new FileInputStream(filename);
    :
}
catch (IOException e)
{
    logger.error(e);
}

If a checked exception is not going to be caught, the programmer must explicitly declare that the caller will have to deal with the exception, as follows.  

private InputStream getInputStream(File file) throws IOException
{
    :
    return new FileInputStream(file);
}

Since checked exceptions are expected to happen, they must be handled.  They cannot simply be ignored in the hope that they will go away.

blog comments powered by Disqus