1 // exception.cxx - implementation of SimGear base exceptions.
2 // Started Summer 2001 by David Megginson, david@megginson.com
3 // This code is released into the Public Domain.
8 #include "exception.hxx"
12 ////////////////////////////////////////////////////////////////////////
13 // Implementation of sg_location class.
14 ////////////////////////////////////////////////////////////////////////
16 sg_location::sg_location ()
24 sg_location::sg_location (const string &path, int line, int column)
32 sg_location::~sg_location ()
37 sg_location::getPath () const
43 sg_location::setPath (const string &path)
49 sg_location::getLine () const
55 sg_location::setLine (int line)
61 sg_location::getColumn () const
67 sg_location::setColumn (int column)
73 sg_location::getByte () const
79 sg_location::setByte (int byte)
85 sg_location::asString () const
89 if (_path != (string)"") {
91 if (_line != -1 || _column != -1)
95 sprintf(buf, "line %d", _line);
101 sprintf(buf, "column %d", _column);
110 ////////////////////////////////////////////////////////////////////////
111 // Implementation of sg_throwable class.
112 ////////////////////////////////////////////////////////////////////////
114 sg_throwable::sg_throwable ()
120 sg_throwable::sg_throwable (const string &message, const string &origin)
126 sg_throwable::~sg_throwable ()
131 sg_throwable::getMessage () const
137 sg_throwable::getFormattedMessage () const
143 sg_throwable::setMessage (const string &message)
149 sg_throwable::getOrigin () const
155 sg_throwable::setOrigin (const string &origin)
162 ////////////////////////////////////////////////////////////////////////
163 // Implementation of sg_error class.
164 ////////////////////////////////////////////////////////////////////////
166 sg_error::sg_error ()
171 sg_error::sg_error (const string &message, const string &origin)
172 : sg_throwable(message, origin)
176 sg_error::~sg_error ()
182 ////////////////////////////////////////////////////////////////////////
183 // Implementation of sg_exception class.
184 ////////////////////////////////////////////////////////////////////////
186 sg_exception::sg_exception ()
191 sg_exception::sg_exception (const string &message, const string &origin)
192 : sg_throwable(message, origin)
196 sg_exception::~sg_exception ()
202 ////////////////////////////////////////////////////////////////////////
203 // Implementation of sg_io_exception.
204 ////////////////////////////////////////////////////////////////////////
206 sg_io_exception::sg_io_exception ()
211 sg_io_exception::sg_io_exception (const string &message, const string &origin)
212 : sg_exception(message, origin)
216 sg_io_exception::sg_io_exception (const string &message,
217 const sg_location &location,
218 const string &origin)
219 : sg_exception(message, origin),
224 sg_io_exception::~sg_io_exception ()
229 sg_io_exception::getFormattedMessage () const
231 string ret = getMessage();
233 ret += getLocation().asString();
238 sg_io_exception::getLocation () const
244 sg_io_exception::setLocation (const sg_location &location)
246 _location = location;
251 ////////////////////////////////////////////////////////////////////////
252 // Implementation of sg_format_exception.
253 ////////////////////////////////////////////////////////////////////////
255 sg_format_exception::sg_format_exception ()
261 sg_format_exception::sg_format_exception (const string &message,
263 const string &origin)
264 : sg_exception(message, origin),
269 sg_format_exception::~sg_format_exception ()
274 sg_format_exception::getText () const
280 sg_format_exception::setText (const string &text)
287 ////////////////////////////////////////////////////////////////////////
288 // Implementation of sg_range_exception.
289 ////////////////////////////////////////////////////////////////////////
291 sg_range_exception::sg_range_exception ()
296 sg_range_exception::sg_range_exception (const string &message,
297 const string &origin)
298 : sg_exception(message, origin)
302 sg_range_exception::~sg_range_exception ()
307 // end of exception.cxx