Safir SDK Core
Loading...
Searching...
No Matches
LibraryExceptions.h
Go to the documentation of this file.
1/******************************************************************************
2*
3* Copyright Saab AB, 2007-2013 (http://safirsdkcore.com)
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#pragma once
26
27#include <unordered_map>
28#include <mutex>
31
32
33#define CATCH_LIBRARY_EXCEPTIONS_AND_RUN(statement) \
34 catch (const Safir::Dob::Typesystem::FundamentalException & exc) \
35 {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc); statement;} \
36 catch (const Safir::Dob::Typesystem::Exception & exc) \
37 {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc); statement;} \
38 catch (const std::exception & exc) \
39 {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc); statement;} \
40 catch (...) \
41 {Safir::Dob::Typesystem::LibraryExceptions::Instance().SetUnknown(); statement;}
42
43#define CATCH_LIBRARY_EXCEPTIONS \
44 catch (const Safir::Dob::Typesystem::FundamentalException & exc) \
45 {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc);} \
46 catch (const Safir::Dob::Typesystem::Exception & exc) \
47 {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc);} \
48 catch (const std::exception & exc) \
49 {Safir::Dob::Typesystem::LibraryExceptions::Instance().Set(exc);} \
50 catch (...) \
51 {Safir::Dob::Typesystem::LibraryExceptions::Instance().SetUnknown();}
52
53
54namespace Safir
55{
56namespace Dob
57{
58namespace Typesystem
59{
64 {
65 public:
72
100 void Set(const FundamentalException & exception);
101
102
130 void Set(const Exception & exception);
131
132
160 void Set(const std::exception & exception);
161
162
187
194 void AppendDescription(const std::wstring & moreDescription);
195
202 void Throw();
203
215 typedef void (*ThrowExceptionCallback)(const std::wstring & description);
216
225 bool RegisterException(const TypeId exceptionId, ThrowExceptionCallback throwFunction);
226
240 void Throw(const TypeId exceptionId, const std::string& description) const;
241
242 private:
245 LibraryExceptions(const LibraryExceptions&) = delete;
246 LibraryExceptions& operator=(const LibraryExceptions&) = delete;
247
248 void Set(const Internal::CommonExceptionBase & exception);
249
250 class Impl;
251
252 Impl* m_impl;
259 struct SingletonHelper
260 {
261 private:
262 friend LibraryExceptions& LibraryExceptions::Instance();
263
264 static LibraryExceptions& Instance();
265 static std::once_flag m_onceFlag;
266 };
267 };
268}
269}
270}
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
DotsC_TypeId TypeId
A unique type identifier.
Definition Defs.h:218
Common functionality for the exception hierarchy of the DOB typesystem.
Definition Exceptions.h:73
This is the base class of all Fundamental Exceptions.
Definition Exceptions.h:200
This is the base class of all (non-Fundamental) Exceptions.
Definition Exceptions.h:233
Contains methods used when passing exceptions across language boundaries.
Definition LibraryExceptions.h:64
void Throw()
Throw the current exception.
void AppendDescription(const std::wstring &moreDescription)
Append some text to the description of the current exception.
void Set(const FundamentalException &exception)
Set the current exception.
static LibraryExceptions & Instance()
Get the instance of the singleton.
void SetUnknown()
Set the current exception.
void Set(const std::exception &exception)
Set the current exception.
void Set(const Exception &exception)
Set the current exception.
void Throw(const TypeId exceptionId, const std::string &description) const
Throw a specific exception.
bool RegisterException(const TypeId exceptionId, ThrowExceptionCallback throwFunction)
Register an exception with the object factory.
#define DOTS_CPP_API
Definition Defs.h:33