source: nrEngine/include/Exception.h @ 30

Revision 30, 4.4 KB checked in by art, 12 years ago (diff)

::std wurde durch std ueberall ersetzt!

Line 
1/***************************************************************************
2 *                                                                         *
3 *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
4 *       mailto: <tevs@mpi-sb.mpg.de>                                      *
5 *                                                                         *
6 *   This program is free software; you can redistribute it and/or modify  *
7 *   it under the terms of the GNU General Public License as published by  *
8 *   the Free Software Foundation; either version 2 of the License, or     *
9 *   (at your option) any later version.                                   *
10 *                                                                         *
11 ***************************************************************************/
12
13#ifndef __NR_EXCEPTION_C_H_
14#define __NR_EXCEPTION_C_H_
15
16
17//----------------------------------------------------------------------------------
18// Includes
19//----------------------------------------------------------------------------------
20#include "Prerequisities.h"
21
22
23/**
24 * This is a macro which throw an exception object
25 * \ingroup error
26 **/
27#define NR_EXCEPT( num, desc, src ) throw( ::nrEngine::Exception( num, desc, src, __FILE__, __LINE__ ) )
28
29/**
30 * Assertion definition used in the engine. This assertion will produce more readable text.
31 * \ingroup error
32 **/ 
33#define NR_ASSERT( exp )        ::nrEngine::Exception::Assert(exp, #exp, __FILE__, "" , __LINE__ )
34
35
36namespace nrEngine{
37
38        //! Exception thrown by the engine if any non returnable error occurs
39        /**
40        * \par
41        *       nrEngine does use return codes to indicate that an error occurs. This is done because
42        *       of performance and code styling reasons. So the user does not have to encapsulate
43        *       each function call of the engine into try{}catch(){} block. Instead of this just
44        *       only check the return value of the function.<br>
45        *       But sometimtes we need to throw an error instead of return back an error code.
46        *       This is done for example in constructors and destructors, where you are not able
47        *       to return any value.<br>
48        *       For such cases you have to catch up the error thrown by the engine. Each exception
49        *       object is of this class.
50        *
51        * \par
52        *       Probably in next releases of the engine we will go away from the return codes to
53        *       the exception system.
54        *
55        * \ingroup error
56        **/
57        class _NRExport Exception
58        {
59                public:
60                        /**
61                        * Default constructor.
62                        * \param number Error code. Can be combined of more than one error code
63                        * \param description Description of the esception
64                        * \param source Where was exception thrown (function name)
65                        */
66                        Exception( Result number, const std::string& description, const std::string& source );
67       
68                        /**
69                        * Advanced constructor.
70                        * \param number Error code. Can be combined of more than one error code
71                        * \param description Description of the esception
72                        * \param source Where was exception thrown (function name)
73                        * \param file In which file was the exception
74                        * \param line Where was the exception thrown
75                        */
76                        Exception( Result number, const std::string& description, const std::string& source, char* file, long line );
77       
78                        /**
79                        * Copy constructor.
80                        */
81                        Exception(const Exception& rhs);
82
83               
84                        /**
85                         * Assert function declared as static to allow using without initialisation
86                         * of the object itself. This function will generate a formatted
87                         * error message and will log it.
88                         * @param exp Boolean expression to be checked (false = fail)
89                         * @param szExp Error message
90                         * @param szFilename Filename of the file where error happens
91                         * @param szFuncName Name of the function where assertion is checked
92                         * @param iLineNum Line number where assert fails
93                         **/
94                        static void Assert(bool exp, const char *szExp, const char *szFilename, const char* szFuncName, int iLineNum);
95
96                private:
97                        long                    lineNumber;
98                        std::string     description;
99                        std::string     source;
100                        std::string     file;
101                        Result                  number;
102
103                       
104                        /**
105                        * Generate the formatted assert error message.
106                        * We use two functions to allow compiler to optimize the assertion
107                        * calls.
108                        **/
109                        static void _assertMsg(const char *szExp, const char *szFilename, const char* szFuncName, int iLineNum);
110
111                        /**
112                         * Give some message to log files
113                         **/
114                        static void _log(const char *szExp, const char *szFilename, const char* szFuncName, int iLineNum, const char* msg);
115        };
116       
117}; // end namespace
118
119#endif
Note: See TracBrowser for help on using the repository browser.