| 1 | package ezvcard.io; |
| 2 | |
| 3 | import ezvcard.Messages; |
| 4 | |
| 5 | /* |
| 6 | Copyright (c) 2012-2023, Michael Angstadt |
| 7 | All rights reserved. |
| 8 | |
| 9 | Redistribution and use in source and binary forms, with or without |
| 10 | modification, are permitted provided that the following conditions are met: |
| 11 | |
| 12 | 1. Redistributions of source code must retain the above copyright notice, this |
| 13 | list of conditions and the following disclaimer. |
| 14 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 15 | this list of conditions and the following disclaimer in the documentation |
| 16 | and/or other materials provided with the distribution. |
| 17 | |
| 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | /** |
| 31 | * Thrown during the unmarshalling of a vCard property to signal that the |
| 32 | * property's value could not be parsed (for example, being unable to parse a |
| 33 | * date string). |
| 34 | * @author Michael Angstadt |
| 35 | */ |
| 36 | public class CannotParseException extends RuntimeException { |
| 37 | private static final long serialVersionUID = -7230344536456543576L; |
| 38 | private final Integer code; |
| 39 | private final Object args[]; |
| 40 | |
| 41 | public CannotParseException() { |
| 42 | this(null); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Creates a new "cannot parse" exception. |
| 47 | * @param code the warning message code |
| 48 | * @param args the warning message arguments |
| 49 | */ |
| 50 | public CannotParseException(int code, Object... args) { |
| 51 | this.code = code; |
| 52 | this.args = args; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Creates a new "cannot parse" exception. |
| 57 | * @param reason the reason why the property value cannot be parsed |
| 58 | */ |
| 59 | public CannotParseException(String reason) { |
| 60 | this(25, reason); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Gets the warning message code. |
| 65 | * @return the message code |
| 66 | */ |
| 67 | public Integer getCode() { |
| 68 | return code; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Gets the warning message arguments. |
| 73 | * @return the message arguments |
| 74 | */ |
| 75 | public Object[] getArgs() { |
| 76 | return args; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public String getMessage() { |
| 81 | return Messages.INSTANCE.getParseMessage(code, args); |
| 82 | } |
| 83 | } |