001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022
023package org.biojava.bio.symbol;
024
025import org.biojava.bio.BioException;
026
027/**
028 * The exception to indicate that a symbol is not valid within a context.
029 * <p>
030 * The usual reason for throwing an IllegalSymbolException is that you are
031 * trying to add a symbol to a sequence with an alpabet that does not contain
032 * the symbol. This is the sequence/alphabet equivalent of a ClassCastException
033 * for objects.
034 * <p>
035 * Frequently, these excepions are actualy generated from Alphabet.validate.
036 *
037 * @author Matthew Pocock
038 */
039public class IllegalSymbolException extends BioException {
040  private final Symbol sym;
041
042  /**
043   * Retrieve the symbol that caused this exception, or null.
044   */
045  public Symbol getSymbol() {
046    return sym;
047  }
048
049  /**
050   * Make the exception with a message.
051   */
052  public IllegalSymbolException(String message) {
053    this(null, null, message);
054  }
055
056  /**
057   * Make the exception with a message and a symbol.
058   */
059  public IllegalSymbolException(Symbol sym, String message) {
060    this(null, sym, message);
061  }
062
063  public IllegalSymbolException(Throwable cause, String message) {
064    this(cause, null, message);
065  }
066
067  public IllegalSymbolException(Throwable cause, Symbol sym, String message) {
068    super(message, cause);
069    this.sym = sym;
070  }
071}