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
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::setMessage (const string &message)
143 sg_throwable::getOrigin () const
149 sg_throwable::setOrigin (const string &origin)
156 sg_throwable::clone () const
158 return new sg_throwable(getMessage(), getOrigin());
164 ////////////////////////////////////////////////////////////////////////
165 // Implementation of sg_error class.
166 ////////////////////////////////////////////////////////////////////////
168 sg_error::sg_error ()
173 sg_error::sg_error (const string &message, const string &origin)
174 : sg_throwable(message, origin)
178 sg_error::~sg_error ()
183 sg_error::clone () const
185 return new sg_error(getMessage(), getOrigin());
190 ////////////////////////////////////////////////////////////////////////
191 // Implementation of sg_exception class.
192 ////////////////////////////////////////////////////////////////////////
194 sg_exception::sg_exception ()
199 sg_exception::sg_exception (const string &message, const string &origin)
200 : sg_throwable(message, origin)
204 sg_exception::~sg_exception ()
209 sg_exception::clone () const
211 return new sg_exception(getMessage(), getOrigin());
216 ////////////////////////////////////////////////////////////////////////
217 // Implementation of sg_io_exception.
218 ////////////////////////////////////////////////////////////////////////
220 sg_io_exception::sg_io_exception ()
225 sg_io_exception::sg_io_exception (const string &message, const string &origin)
226 : sg_exception(message, origin)
230 sg_io_exception::sg_io_exception (const string &message,
231 const sg_location &location,
232 const string &origin)
233 : sg_exception(message, origin),
238 sg_io_exception::~sg_io_exception ()
243 sg_io_exception::getLocation () const
249 sg_io_exception::setLocation (const sg_location &location)
251 _location = location;
255 sg_io_exception::clone () const
257 return new sg_io_exception(getMessage(), getLocation(), getOrigin());
263 ////////////////////////////////////////////////////////////////////////
264 // Implementation of sg_format_exception.
265 ////////////////////////////////////////////////////////////////////////
267 sg_format_exception::sg_format_exception ()
273 sg_format_exception::sg_format_exception (const string &message,
275 const string &origin)
276 : sg_exception(message, origin),
281 sg_format_exception::~sg_format_exception ()
286 sg_format_exception::getText () const
292 sg_format_exception::setText (const string &text)
297 sg_format_exception *
298 sg_format_exception::clone () const
300 return new sg_format_exception(getMessage(), getText(), getOrigin());
305 ////////////////////////////////////////////////////////////////////////
306 // Implementation of sg_range_exception.
307 ////////////////////////////////////////////////////////////////////////
309 sg_range_exception::sg_range_exception ()
314 sg_range_exception::sg_range_exception (const string &message,
315 const string &origin)
316 : sg_exception(message, origin)
320 sg_range_exception::~sg_range_exception ()
325 sg_range_exception::clone () const
327 return new sg_range_exception(getMessage(), getOrigin());
331 // end of exception.cxx