Home  >  Article  >  Java  >  How to include fault capture information in detailed message in java

How to include fault capture information in detailed message in java

WBOY
WBOYforward
2023-05-20 23:10:05965browse

Include fault capture information in the detailed message

private OutputStream openOutputStream(File file) throws IOException {
    if (file.exists()) {
        if (file.isDirectory()) {
            throw new IOException("File '" + file + "' exists but is a directory");
        }
        if (!file.canWrite()) {
            throw new IOException("File '" + file + "' cannot be written to");
        }
    } else {
        final File parent = file.getParentFile();
        if (parent != null) {
            if (!parent.mkdirs() && !parent.isDirectory()) {
                throw new IOException("Directory '" + parent + "' could not be created");
            }
        }
    }
    return new FileOutputStream(file, false);
}

In this method, IOException Use different strings to pass different fault capture information.

The above is the detailed content of How to include fault capture information in detailed message in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete