View Javadoc
1   /*
2    * CSVeed (https://github.com/42BV/CSVeed)
3    *
4    * Copyright 2013-2023 CSVeed.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of The Apache Software License,
8    * Version 2.0 which accompanies this distribution, and is available at
9    * https://www.apache.org/licenses/LICENSE-2.0.txt
10   */
11  package org.csveed.report;
12  
13  import org.slf4j.Logger;
14  import org.slf4j.LoggerFactory;
15  
16  /**
17   * The Class CsvException.
18   */
19  public class CsvException extends RuntimeException {
20  
21      /** The Constant serialVersionUID. */
22      private static final long serialVersionUID = 1L;
23  
24      /** The Constant LOG. */
25      private static final Logger LOG = LoggerFactory.getLogger(CsvException.class);
26  
27      /** The error. */
28      private CsvError error;
29  
30      /**
31       * Instantiates a new csv exception.
32       *
33       * @param error
34       *            the error
35       */
36      public CsvException(CsvError error) {
37          this.error = error;
38          for (String line : error.getPrintableLines()) {
39              LOG.error("{}", line);
40          }
41      }
42  
43      /**
44       * Gets the error.
45       *
46       * @return the error
47       */
48      public CsvError getError() {
49          return this.error;
50      }
51  
52      @Override
53      public String getMessage() {
54          return this.getError().getMessage();
55      }
56  
57      @Override
58      public String getLocalizedMessage() {
59          StringBuilder errorMessage = new StringBuilder();
60          boolean first = true;
61          for (String line : getError().getPrintableLines()) {
62              if (!first) {
63                  errorMessage.append(System.lineSeparator());
64              }
65              errorMessage.append(line);
66              first = false;
67          }
68          return errorMessage.toString();
69      }
70  
71  }