diff options
author | Tim Allison <tallison@apache.org> | 2017-07-26 18:43:27 +0000 |
---|---|---|
committer | Tim Allison <tallison@apache.org> | 2017-07-26 18:43:27 +0000 |
commit | b1a0c7d53d72467669f6cc47e2dbe353391fa98c (patch) | |
tree | 122f708ca39a7dff2d7d66596e354b3b976e7372 /src/java | |
parent | a9c40720714e54bace78e9dc4e923f4af59f1a78 (diff) | |
download | poi-b1a0c7d53d72467669f6cc47e2dbe353391fa98c.tar.gz poi-b1a0c7d53d72467669f6cc47e2dbe353391fa98c.zip |
61337 -- try to convert assertions to exceptions. I left in the assertions for the binary search components.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1803092 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/org/apache/poi/util/DocumentFormatException.java | 53 | ||||
-rw-r--r-- | src/java/org/apache/poi/util/RecordFormatException.java | 14 |
2 files changed, 67 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/util/DocumentFormatException.java b/src/java/org/apache/poi/util/DocumentFormatException.java new file mode 100644 index 0000000000..e53202235c --- /dev/null +++ b/src/java/org/apache/poi/util/DocumentFormatException.java @@ -0,0 +1,53 @@ + +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + + +package org.apache.poi.util; + +/** + * This is similar to {@link RecordFormatException}, except this is thrown + * when there's a higher order problem with parsing a document beyond individual records. + */ +public class DocumentFormatException extends RuntimeException { + + public DocumentFormatException(String exception) { + super(exception); + } + + public DocumentFormatException(String exception, Throwable thr) { + super(exception, thr); + } + + public DocumentFormatException(Throwable thr) { + super(thr); + } + + /** + * Syntactic sugar to check whether a DocumentFormatException should + * be thrown. If assertTrue is <code>false</code>, this will throw this + * exception with the message. + * + * @param assertTrue + * @param message + */ + public static void check(boolean assertTrue, String message) { + if (!assertTrue) { + throw new DocumentFormatException(message); + } + } +} diff --git a/src/java/org/apache/poi/util/RecordFormatException.java b/src/java/org/apache/poi/util/RecordFormatException.java index d1643b8be0..2bc4ba3bcb 100644 --- a/src/java/org/apache/poi/util/RecordFormatException.java +++ b/src/java/org/apache/poi/util/RecordFormatException.java @@ -39,4 +39,18 @@ public class RecordFormatException public RecordFormatException(Throwable thr) { super(thr); } + + /** + * Syntactic sugar to check whether a RecordFormatException should + * be thrown. If assertTrue is <code>false</code>, this will throw this + * exception with the message. + * + * @param assertTrue + * @param message + */ + public static void check(boolean assertTrue, String message) { + if (! assertTrue) { + throw new RecordFormatException(message); + } + } } |