TLELib  0.1.0
tleexception.h
Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------+
00002  | TLELib                                                                      |
00003  | Copyright 2011 Sergei V. Fundaev                                            |
00004  +-----------------------------------------------------------------------------+
00005  | This file is part of TLELib.                                                |
00006  |                                                                             |
00007  | TLELib is free software: you can redistribute it and/or modify              |
00008  | it under the terms of the GNU Lesser General Public License as published by |
00009  | the Free Software Foundation, either version 3 of the License, or           |
00010  | (at your option) any later version.                                         |
00011  |                                                                             |
00012  | TLELib is distributed in the hope that it will be useful,                   |
00013  | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00014  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00015  | GNU Lesser General Public License for more details.                         |
00016  |                                                                             |
00017  | You should have received a copy of the GNU Lesser General Public License    |
00018  | along with TLELib. If not, see <http://www.gnu.org/licenses/>.              |
00019  +----------------------------------------------------------------------------*/
00025 #include <string>
00026 #include <exception>
00027 #include <stdexcept>
00028 
00029 #ifndef TLEEXCEPTION_H
00030 #define TLEEXCEPTION_H
00031 
00032 namespace tlelib
00033 {
00034 
00040 class tle_too_short_string: public std::runtime_error
00041 {
00042     std::string m_line; 
00043 public:
00048     tle_too_short_string(const std::string& line)
00049         : std::runtime_error("Too short string: " + line)
00050     {
00051         m_line = line;
00052     }
00053     virtual ~tle_too_short_string() throw() {} 
00054 
00058     std::string line() const throw() { return m_line; }
00059 };
00060 //------------------------------------------------------------------------------
00061 
00066 class tle_invalid_format: public std::runtime_error
00067 {
00068     std::string m_line; 
00069 public:
00074     tle_invalid_format(const std::string& line) : std::runtime_error("Invalid element format in line: \"" + line + "\".")
00075     {
00076         m_line = line;
00077     }
00078     virtual ~tle_invalid_format() throw() {} 
00079 
00083     std::string line() const throw() { return m_line; }
00084 };
00085 //------------------------------------------------------------------------------
00086 
00091 class tle_checksum_error: public std::runtime_error
00092 {
00093     std::string m_line; 
00094     int m_expected_checksum, 
00095         m_actual_checksum;   
00096 public:
00103     tle_checksum_error(const std::string& line, const int expected_checksum, const int actual_checksum)
00104         : std::runtime_error("Invalid checksum in line \""+ line +"\". Expected checksum: " + int2string(expected_checksum) + ". Actual checksum: " + int2string(expected_checksum) + ".")
00105     {
00106         m_line = line;
00107         m_expected_checksum = expected_checksum;
00108         m_actual_checksum = actual_checksum;
00109     }
00110     virtual ~tle_checksum_error() throw() {} 
00111 
00115     std::string line() const throw() { return m_line; }
00120     int expected_checksum() const throw() { return m_expected_checksum; }
00125     int actual_checksum() const throw() { return m_actual_checksum; }
00126 };
00127 //------------------------------------------------------------------------------
00128 
00129 } // namespace
00130 
00131 #endif // TLEEXCEPTION_H
 All Classes Namespaces Files Functions Variables Defines