3 * Interface definition for SimGear base exceptions.
4 * Started Spring 2001 by David Megginson, david@megginson.com
5 * This code is released into the Public Domain.
10 #ifndef __SIMGEAR_MISC_EXCEPTION_HXX
11 #define __SIMGEAR_MISC_EXCEPTION_HXX 1
13 #include <simgear/compiler.h>
20 * Information encapsulating a single location in an external resource
22 * A position in the resource my optionally be provided, either by
23 * line number, line number and column number, or byte offset from the
24 * beginning of the resource.
30 sg_location (const string &path, int line = -1, int column = -1);
31 virtual ~sg_location ();
32 virtual const string &getPath () const;
33 virtual void setPath (const string &path);
34 virtual int getLine () const;
35 virtual void setLine (int line);
36 virtual int getColumn () const;
37 virtual void setColumn (int column);
38 virtual int getByte () const;
39 virtual void setByte (int byte);
40 virtual string asString () const;
50 * Abstract base class for all throwables.
56 sg_throwable (const string &message, const string &origin = "");
57 virtual ~sg_throwable ();
58 virtual const string &getMessage () const;
59 virtual const string getFormattedMessage () const;
60 virtual void setMessage (const string &message);
61 virtual const string &getOrigin () const;
62 virtual void setOrigin (const string &origin);
71 * An unexpected fatal error.
73 * Methods and functions show throw this exception when something
74 * very bad has happened (such as memory corruption or
75 * a totally unexpected internal value). Applications should catch
76 * this exception only at the top level if at all, and should
77 * normally terminate execution soon afterwards.
79 class sg_error : public sg_throwable
83 sg_error (const string &message, const string &origin = "");
89 * Base class for all SimGear exceptions.
91 * SimGear-based code should throw this exception only when no
92 * more specific exception applies. It may not be caught until
93 * higher up in the application, where it is not possible to
94 * resume normal operations if desired.
96 * A caller can catch sg_exception by default to ensure that
97 * all exceptions are caught. Every SimGear exception can contain
98 * a human-readable error message and a human-readable string
99 * indicating the part of the application causing the exception
100 * (as an aid to debugging, only).
102 class sg_exception : public sg_throwable
106 sg_exception (const string &message, const string &origin = "");
107 virtual ~sg_exception ();
112 * An I/O-related SimGear exception.
114 * SimGear-based code should throw this exception when it fails
115 * to read from or write to an external resource, such as a file,
116 * socket, URL, or database.
118 * In addition to the functionality of sg_exception, an
119 * sg_io_exception may contain location information, such as the name
120 * of a file or URL, and possible also a location in that file or URL.
122 class sg_io_exception : public sg_exception
126 sg_io_exception (const string &message, const string &origin = "");
127 sg_io_exception (const string &message, const sg_location &location,
128 const string &origin = "");
129 virtual ~sg_io_exception ();
130 virtual const string getFormattedMessage () const;
131 virtual const sg_location &getLocation () const;
132 virtual void setLocation (const sg_location &location);
134 sg_location _location;
139 * A format-related SimGear exception.
141 * SimGear-based code should throw this exception when a string
142 * does not appear in the expected format (for example, a date
143 * string does not conform to ISO 8601).
145 * In addition to the functionality of sg_exception, an
146 * sg_format_exception can contain a copy of the original malformated
149 class sg_format_exception : public sg_exception
152 sg_format_exception ();
153 sg_format_exception (const string &message, const string &text,
154 const string &origin = "");
155 virtual ~sg_format_exception ();
156 virtual const string &getText () const;
157 virtual void setText (const string &text);
164 * A range-related SimGear exception.
166 * SimGear-based code should throw this exception when a value falls
167 * outside the range where it can reasonably be handled; examples
168 * include longitude outside the range -180:180, unrealistically high
169 * forces or velocities, an illegal airport code, etc. A range
170 * exception usually means that something has gone wrong internally.
172 class sg_range_exception : public sg_exception
175 sg_range_exception ();
176 sg_range_exception (const string &message, const string &origin = "");
177 virtual ~sg_range_exception ();
182 // end of exception.hxx