Ice 3.7 C++11 API Reference
UserExceptionFactory.h
Go to the documentation of this file.
1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #ifndef ICE_USER_EXCEPTION_FACTORY_H
6 #define ICE_USER_EXCEPTION_FACTORY_H
7 
8 #include <IceUtil/Shared.h>
9 #include <IceUtil/Handle.h>
10 #include <Ice/Config.h>
11 
12 #ifdef ICE_CPP11_MAPPING
13 
14 namespace Ice
15 {
16 
18 using UserExceptionFactory = std::function<void(const std::string&)>;
19 
20 }
21 
22 namespace IceInternal
23 {
24 
25 template<class E>
26 void
27 #ifdef NDEBUG
28 defaultUserExceptionFactory(const std::string&)
29 #else
30 defaultUserExceptionFactory(const std::string& typeId)
31 #endif
32 {
33  assert(typeId == E::ice_staticId());
34  throw E();
35 }
36 
37 }
38 #else
39 
40 namespace Ice
41 {
42 
48 {
49 public:
50 
51  virtual void createAndThrow(const ::std::string&) = 0;
52  virtual ~UserExceptionFactory();
53 };
54 typedef ::IceUtil::Handle<UserExceptionFactory> UserExceptionFactoryPtr;
55 
56 }
57 
58 namespace IceInternal
59 {
60 
61 template<class E>
62 class DefaultUserExceptionFactory : public Ice::UserExceptionFactory
63 {
64 public:
65 
66  DefaultUserExceptionFactory(const ::std::string& typeId) :
67  _typeId(typeId)
68  {
69  }
70 
71 #ifdef NDEBUG
72  virtual void createAndThrow(const ::std::string&)
73 #else
74  virtual void createAndThrow(const ::std::string& typeId)
75 #endif
76  {
77  assert(typeId == _typeId);
78  throw E();
79  }
80 
81 private:
82  const ::std::string _typeId;
83 };
84 
85 }
86 
87 #endif
88 #endif
Handle.h
ICE_API
#define ICE_API
Definition: Config.h:197
Shared.h
Config.h
Ice
Definition: BuiltinSequences.h:56
Ice::UserExceptionFactory
std::function< void(const std::string &)> UserExceptionFactory
Creates and throws a user exception.
Definition: UserExceptionFactory.h:18
IceUtil::Shared
Definition: Shared.h:78