← joda-money / src/main/java/org/joda/money/format/MoneyFormatException.java
| 1 | /* |
| 2 | * Copyright 2009-present, Stephen Colebourne |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.joda.money.format; |
| 17 | |
| 18 | import java.io.IOException; |
| 19 | |
| 20 | /** |
| 21 | * Exception thrown during monetary formatting. |
| 22 | * <p> |
| 23 | * This exception makes no guarantees about immutability or thread-safety. |
| 24 | */ |
| 25 | public class MoneyFormatException extends RuntimeException { |
| 26 | |
| 27 | /** Serialization lock. */ |
| 28 | private static final long serialVersionUID = 87533576L; |
| 29 | |
| 30 | /** |
| 31 | * Constructor taking a message. |
| 32 | * |
| 33 | * @param message the message |
| 34 | */ |
| 35 | public MoneyFormatException(String message) { |
| 36 | super(message); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Constructor taking a message and cause. |
| 41 | * |
| 42 | * @param message the message |
| 43 | * @param cause the exception cause |
| 44 | */ |
| 45 | public MoneyFormatException(String message, Throwable cause) { |
| 46 | super(message, cause); |
| 47 | } |
| 48 | |
| 49 | //----------------------------------------------------------------------- |
| 50 | /** |
| 51 | * Checks if the cause of this exception was an IOException, and if so re-throws it |
| 52 | * <p> |
| 53 | * This method is useful if you call a printer with an open stream or |
| 54 | * writer and want to ensure that IOExceptions are not lost. |
| 55 | * <pre> |
| 56 | * try { |
| 57 | * printer.print(writer, money); |
| 58 | * } catch (CalendricalFormatException ex) { |
| 59 | * ex.rethrowIOException(); |
| 60 | * // if code reaches here exception was caused by issues other than IO |
| 61 | * } |
| 62 | * </pre> |
| 63 | * Note that calling this method will re-throw the original IOException, |
| 64 | * causing this MoneyFormatException to be lost. |
| 65 | * |
| 66 | * @throws IOException if the cause of this exception is an IOException |
| 67 | */ |
| 68 | public void rethrowIOException() throws IOException { |
| 69 | if (getCause() instanceof IOException) { |
| 70 | throw (IOException) getCause(); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | } |
| 75 |