1 /*      _______   __   __   __   ______   __   __   _______   __   __
2  *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
3  *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
4  *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
5  *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
6  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
7  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
8  *
9  * Copyright (c) 2004, 2005 darkbits                        Js_./
10  * Per Larsson a.k.a finalman                          _RqZ{a<^_aa
11  * Olof Naess�n a.k.a jansem/yakslem                _asww7!uY`>  )\a//
12  *                                                 _Qhm`] _f "'c  1!5m
13  * Visit: http://guichan.darkbits.org             )Qk<P ` _: :+' .'  "{[
14  *                                               .)j(] .d_/ '-(  P .   S
15  * License: (BSD)                                <Td/Z <fP"5(\"??"\a.  .L
16  * Redistribution and use in source and          _dV>ws?a-?'      ._/L  #'
17  * binary forms, with or without                 )4d[#7r, .   '     )d`)[
18  * modification, are permitted provided         _Q-5'5W..j/?'   -?!\)cam'
19  * that the following conditions are met:       j<<WP+k/);.        _W=j f
20  * 1. Redistributions of source code must       .$%w\/]Q  . ."'  .  mj$
21  *    retain the above copyright notice,        ]E.pYY(Q]>.   a     J@\
22  *    this list of conditions and the           j(]1u<sE"L,. .   ./^ ]{a
23  *    following disclaimer.                     4'_uomm\.  )L);-4     (3=
24  * 2. Redistributions in binary form must        )_]X{Z('a_"a7'<a"a,  ]"[
25  *    reproduce the above copyright notice,       #}<]m7`Za??4,P-"'7. ).m
26  *    this list of conditions and the            ]d2e)Q(<Q(  ?94   b-  LQ/
27  *    following disclaimer in the                <B!</]C)d_, '(<' .f. =C+m
28  *    documentation and/or other materials      .Z!=J ]e []('-4f _ ) -.)m]'
29  *    provided with the distribution.          .w[5]' _[ /.)_-"+?   _/ <W"
30  * 3. Neither the name of Guichan nor the      :$we` _! + _/ .        j?
31  *    names of its contributors may be used     =3)= _f  (_yQmWW$#(    "
32  *    to endorse or promote products derived     -   W,  sQQQQmZQ#Wwa]..
33  *    from this software without specific        (js, \[QQW$QWW#?!V"".
34  *    prior written permission.                    ]y:.<\..          .
35  *                                                 -]n w/ '         [.
36  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT       )/ )/           !
37  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY         <  (; sac    ,    '
38  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,               ]^ .-  %
39  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF            c <   r
40  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR            aga<  <La
41  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE          5%  )P'-3L
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR        _bQf` y`..)a
43  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,          ,J?4P'.P"_(\?d'.,
44  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES               _Pa,)!f/<[]/  ?"
45  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT      _2-..:. .r+_,.. .
46  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     ?a.<%"'  " -'.a_ _,
47  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION)                     ^
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
49  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
51  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
52  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53  */
54 
55 #ifndef GCN_EXCEPTION_HPP
56 #define GCN_EXCEPTION_HPP
57 
58 #include <string>
59 
60 #include "guichan/platform.h"
61 
62 
63 #if _MSC_VER <= 1200
64 #define __FUNCTION__ "?"
65 #endif
66 
67 /*
68  * A macro to be used when throwing exceptions.
69  * What it basicly does is that it creates a new exception
70  * and automatically sets the filename and line number where
71  * the exception occured.
72  */
73 #define GCN_EXCEPTION(mess) gcn::Exception(mess,   \
74                             __FUNCTION__,          \
75                             __FILE__,              \
76                             __LINE__)
77 
78 namespace gcn
79 {
80 
81     /**
82      * An exception containing a message, a file and a line number.
83      * Guichan will only throw exceptions of this class. You can use
84      * this class for your own exceptions. A nifty feature of the
85      * excpetion class is that it can tell you from which line and
86      * file it was thrown. To make things easier when throwing
87      * exceptions there exists a macro for creating exceptions
88      * which automatically sets the filename and line number.
89      *
90      * EXAMPLE: @code
91      *          throw GCN_EXCEPTION("my error message");
92      *          @endcode
93      */
94     class GCN_CORE_DECLSPEC Exception
95     {
96     public:
97 
98         /**
99          * Constructor.
100          */
101         Exception();
102 
103         /**
104          * Constructor.
105          *
106          * @param message the error message.
107          */
108         Exception(const std::string& message);
109 
110         /**
111          * Constructor.
112          *
113          * NOTE: Don't use this constructor. Use the GCN_EXCEPTION macro instead.
114          *
115          * @param message the error message.
116          * @param function the function name.
117          * @param filename the name of the file.
118          * @param line the line number.
119          */
120         Exception(const std::string& message,
121                   const std::string& function,
122                   const std::string& filename,
123                   int line);
124 
125         /**
126          * Gets the function name in which the exception was thrown.
127          *
128          * @return the function name in which the exception was thrown.
129          */
130         const std::string& getFunction() const;
131 
132         /**
133          * Gets the error message of the exception.
134          *
135          * @return the error message.
136          */
137         const std::string& getMessage() const;
138 
139         /**
140          * Gets the filename in which the exceptions was thrown.
141          *
142          * @return the filename in which the exception was thrown.
143          */
144         const std::string& getFilename() const;
145 
146         /**
147          * Gets the line number of the line where the exception was thrown.
148          *
149          * @return the line number of the line where the exception was thrown.
150          */
151         int getLine() const;
152 
153     protected:
154         std::string mFunction;
155         std::string mMessage;
156         std::string mFilename;
157         int mLine;
158     };
159 }
160 
161 #endif // end GCN_EXCEPTION_HPP
162 
163 /*
164  * "Final Fantasy XI is the BEST!... It's even better then water!"
165  *  - Astrolite
166  * I believe it's WoW now days.
167  */
168