View Javadoc
1   package uk.ac.ebi.intenz.webapp.exceptions;
2   
3   import java.sql.SQLException;
4   
5   /**
6    * This exception is a wrapper around the SQLException.
7    *
8    * The purpose of this class is to provide either a user friendly version of a SQL exception
9    * or for the programmer the tough details.
10   *
11   * @author Michael Darsow
12   * @version 2.0.0 - 27-February-2004
13   */
14  public class DatabaseException extends Exception {
15    private SQLException sqlException;
16  
17    /**
18     * Initialise this exception with a user friendly message and the <code>SQLException</code> object.
19     *
20     * @param message The self-defined message.
21     * @param sqlException <code>SQLException</code> instance.
22     */
23    public DatabaseException(String message, SQLException sqlException) {
24      super(message);
25      this.sqlException = sqlException;
26    }
27  
28    public DatabaseException(String message) {
29      super(message);
30      this.sqlException = null;
31    }
32  
33    /**
34     * Uses a standard message.
35     *
36     * @param sqlException <code>SQLException</code> instance.
37     */
38    public DatabaseException(SQLException sqlException) {
39      super("\nIt was not possible to retrieve any information from the database." +
40              "\nPresumably the database server is either too busy or down at the moment" +
41              "\nSorry for any inconvenience this error might have caused.\nPlease try again later.");
42      this.sqlException = sqlException;
43    }
44  
45    // --------------------  GETTER & SETTER -----------------------
46  
47    /**
48     * Return the details about this exception.
49     *
50     * @return <code>SQLException</code> message.
51     */
52    public String getSqlExceptionMessage() {
53      return sqlException.toString();
54    }
55  }