1 /*
2 * Copyright 2016 Andrew Rucker Jones.
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 com.opencsv.exceptions;
17
18 /**
19 * This exception indicates that the converter did not behave as expected in
20 * some way.
21 * Typically this is for custom converters and means it could not be
22 * instantiated, but this exception is also used for meaningless values to
23 * annotations associated with opencsv, for example, since this renders the
24 * converter opencsv provides inoperative.
25 *
26 * @author Andrew Rucker Jones
27 * @since 3.8
28 */
29 public class CsvBadConverterException extends CsvRuntimeException {
30 private static final long serialVersionUID = 1L;
31
32 private final Class<?> converterClass;
33
34 /**
35 * Default constructor, in case no further information is necessary or
36 * available.
37 */
38 public CsvBadConverterException() {
39 converterClass = null;
40 }
41
42 /**
43 * Constructor for specifying the class of the offending converter.
44 *
45 * @param converterClass The class of the converter that misbehaved
46 */
47 public CsvBadConverterException(Class<?> converterClass) {
48 this.converterClass = converterClass;
49 }
50
51 /**
52 * Constructor with a simple text.
53 *
54 * @param message Human-readable error text
55 */
56 public CsvBadConverterException(String message) {
57 super(message);
58 converterClass = null;
59 }
60
61 /**
62 * Constructor for setting the class of the converter and an error message.
63 *
64 * @param converterClass Class of the converter that misbehaved
65 * @param message Human-readable error text
66 */
67 public CsvBadConverterException(Class<?> converterClass, String message) {
68 super(message);
69 this.converterClass = converterClass;
70 }
71
72 /**
73 * @return The class of the provided custom converter
74 */
75 public Class<?> getConverterClass() {
76 return converterClass;
77 }
78 }