001/* ----------------------------------------------------------------------------
002   The Kiwi Toolkit - A Java Class Library
003   Copyright (C) 1998-2004 Mark A. Lindner
004
005   This library is free software; you can redistribute it and/or
006   modify it under the terms of the GNU General Public License as
007   published by the Free Software Foundation; either version 2 of the
008   License, or (at your option) any later version.
009
010   This library is distributed in the hope that it will be useful,
011   but WITHOUT ANY WARRANTY; without even the implied warranty of
012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013   General Public License for more details.
014
015   You should have received a copy of the GNU General Public License
016   along with this library; if not, write to the Free Software
017   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018   02111-1307, USA.
019 
020   The author may be contacted at: mark_a_lindner@yahoo.com
021   ----------------------------------------------------------------------------
022   $Log: ParsingException.java,v $
023   Revision 1.6  2004/05/05 22:47:37  markl
024   comment block updates
025
026   Revision 1.5  2003/01/19 09:34:27  markl
027   Javadoc & comment header updates.
028
029   Revision 1.4  2001/03/12 02:18:28  markl
030   Source code cleanup.
031
032   Revision 1.3  1999/06/30 08:17:32  markl
033   Minor fixes to message formatting.
034
035   Revision 1.2  1999/01/10 03:37:18  markl
036   added GPL header & RCS tag
037   ----------------------------------------------------------------------------
038*/
039
040package kiwi.text;
041
042/** General-purpose parsing exception.
043  *
044  * @author Mark Lindner
045  */
046
047public class ParsingException extends Exception
048  {
049  private int line = -1;
050  private String message = "";
051
052  /** Construct a new <code>ParsingException</code>.
053    *
054    * @param message The exception message.
055    */
056
057  public ParsingException(String message)
058    {
059    this(message, -1);
060    }
061
062  /** Construct a new <code>ParsingException</code>.
063    *
064    * @param message The exception message.
065    * @param line The line number in the input where the exception occurred.
066    */
067
068  public ParsingException(String message, int line)
069    {
070    super(message);
071    this.message = message;
072    this.line = line;
073    }
074
075  /** Get the line number of this exception. If no line number is available,
076    * this method returns -1.
077    */
078
079  public int getLine()
080    {
081    return(line);
082    }
083
084  /** Get the message of this exception. */
085
086  public String getMessage()
087    {
088    return(message);
089    }
090
091  /** Convert the parsing exception to a string that contains the message and
092    * line number.
093    */
094
095  public String toString()
096    {
097    String msg = getMessage();
098    if(line >= 0)
099      msg += (" on line " + line);
100    
101    return(msg);
102    }
103
104  }
105
106/* end of source file */