View Javadoc
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  import org.apache.commons.lang3.ArrayUtils;
19  
20  /**
21   * This is the base class for all exceptions for opencsv.
22   *
23   * @author Andrew Rucker Jones
24   * @since 3.8
25   */
26  public class CsvException extends Exception {
27      private static final long serialVersionUID = 1L;
28  
29      private long lineNumber;
30  
31      private String[] line;
32  
33      /**
34       * Default constructor, in case no parameters are required.
35       */
36      public CsvException() {
37          lineNumber = -1;
38      }
39  
40      /**
41       * Constructor that allows a human-readable message.
42       *
43       * @param message The error text
44       */
45      public CsvException(String message) {
46          super(message);
47          lineNumber = -1;
48      }
49  
50      /**
51       * @return The line number that caused the error. This should be the
52       * one-based number of the line that caused the error, not including the
53       * header line, if present.
54       */
55      public long getLineNumber() {
56          return lineNumber;
57      }
58  
59      /**
60       * @param lineNumber The line number that caused the error. This should be the
61       *                   one-based number of the line that caused the error, not including the
62       *                   header line, if present.
63       */
64      public void setLineNumber(long lineNumber) {
65          this.lineNumber = lineNumber;
66      }
67  
68      /**
69       * @return The line that caused the error if reading and the data are
70       * available. Is always {@code null} on errors during writing, and may
71       * also be {@code null} or empty on certain errors that occur during
72       * reading.
73       * @since 4.4
74       */
75      public String[] getLine() {
76          return ArrayUtils.clone(line);
77      }
78  
79      /**
80       * @param line The line that caused the error on reading. May be
81       * {@code null}.
82       * @since 4.4
83       */
84      public void setLine(String[] line) {
85          this.line = ArrayUtils.clone(line);
86      }
87  
88  }