Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LibraryExceptions.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2007-2013 (http://safir.sourceforge.net)
4 *
5 * Created by: Lars Hagström / stlrha
6 *
7 *******************************************************************************
8 *
9 * This file is part of Safir SDK Core.
10 *
11 * Safir SDK Core is free software: you can redistribute it and/or modify
12 * it under the terms of version 3 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * Safir SDK Core is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22 *
23 ******************************************************************************/
24 
25 #ifndef __DOTS_LIBRARY_EXCEPTIONS_H__
26 #define __DOTS_LIBRARY_EXCEPTIONS_H__
27 
28 #include <boost/noncopyable.hpp>
29 #include <boost/thread/once.hpp>
32 
33 #ifdef _MSC_VER
34 #pragma warning (push)
35 #pragma warning (disable: 4251) // warning C4251: 'Safir::Dob::Typesystem::LibraryExceptions::m_CallbackMap' : class 'stdext::hash_map<_Kty,_Ty>' needs to have dll-interface to be used by clients of class 'Safir::Dob::Typesystem::LibraryExceptions'
36 #pragma warning (disable: 4275) // warning C4275: non dll-interface class 'boost::noncopyable_::noncopyable' used as base for dll-interface class 'Safir::Dob::Typesystem::LibraryExceptions'
37 #endif
38 
39 #define CATCH_LIBRARY_EXCEPTIONS_AND_RUN(statement) \
40  catch (const Safir::Dob::Typesystem::FundamentalException & exc) \
41  {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc); statement;} \
42  catch (const Safir::Dob::Typesystem::Exception & exc) \
43  {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc); statement;} \
44  catch (const std::exception & exc) \
45  {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc); statement;} \
46  catch (...) \
47  {Safir::Dob::Typesystem::LibraryExceptions::Instance().SetUnknown(); statement;}
48 
49 #define CATCH_LIBRARY_EXCEPTIONS \
50  catch (const Safir::Dob::Typesystem::FundamentalException & exc) \
51  {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc);} \
52  catch (const Safir::Dob::Typesystem::Exception & exc) \
53  {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc);} \
54  catch (const std::exception & exc) \
55  {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc);} \
56  catch (...) \
57  {Safir::Dob::Typesystem::LibraryExceptions::Instance().SetUnknown();}
58 
59 
60 namespace Safir
61 {
62 namespace Dob
63 {
64 namespace Typesystem
65 {
70  private boost::noncopyable
71  {
72  public:
78  static LibraryExceptions & Instance();
79 
107  void Set(const FundamentalException & exception);
108 
109 
137  void Set(const Exception & exception);
138 
139 
167  void Set(const std::exception & exception);
168 
169 
193  void SetUnknown();
194 
201  void AppendDescription(const std::wstring & moreDescription);
202 
209  void Throw();
210 
222  typedef void (*ThrowExceptionCallback)(const std::wstring & description);
223 
232  bool RegisterException(const TypeId exceptionId, ThrowExceptionCallback throwFunction)
233  {return m_CallbackMap.insert(CallbackMap::value_type(exceptionId,throwFunction)).second;}
234 
248  void Throw(const TypeId exceptionId, const std::string& description) const;
249 
250  private:
253 
254 
255  void Set(const Internal::CommonExceptionBase & exception);
256 
257  typedef unordered_map<TypeId, ThrowExceptionCallback> CallbackMap;
258  CallbackMap m_CallbackMap;
259 
266  struct SingletonHelper
267  {
268  private:
270 
271  static LibraryExceptions& Instance();
272  static boost::once_flag m_onceFlag;
273  };
274  };
275 }
276 }
277 }
278 
279 #ifdef _MSC_VER
280 #pragma warning (pop)
281 #endif
282 
283 #endif
284 
285 
This is the base class of all (non-Fundamental) Exceptions.
Definition: Exceptions.h:223
static LibraryExceptions & Instance()
Get the instance of the singleton.
This is the base class of all Fundamental Exceptions.
Definition: Exceptions.h:190
DotsC_TypeId TypeId
A unique type identifier.
Definition: Defs.h:219
Contains methods used when passing exceptions across language boundaries.
Definition: LibraryExceptions.h:69
bool RegisterException(const TypeId exceptionId, ThrowExceptionCallback throwFunction)
Register an exception with the object factory.
Definition: LibraryExceptions.h:232
Common functionality for the exception hierarchy of the DOB typesystem.
Definition: Exceptions.h:63
#define DOTS_CPP_API
Definition: Defs.h:33