EventAnalysis  1.3.0
RetrievalExceptions.h
Go to the documentation of this file.
1 /*
2  * RetrievalExceptions.h
3  *
4  * Created on: 12 Aug 2020
5  * Author: Nicola Mori
6  */
7 
10 #ifndef RETRIEVALEXCEPTIONS_H_
11 #define RETRIEVALEXCEPTIONS_H_
12 
13 #include "core/Exception.h"
14 #include "core/RetrievalResult.h"
15 
16 namespace EA {
17 
18 namespace Retrieval {
19 
21 class Exception : public EA::Exception {
22 public:
23  Exception(std::string msg = "Exception") : EA::Exception(msg){};
24 };
25 
27 class NotAvailable : public Exception {
28 public:
29  NotAvailable(std::string msg = "NotAvailable") : Exception(msg){};
30 };
31 
33 class BadClass : public Exception {
34 public:
35  BadClass(std::string msg = "BadClass") : Exception(msg){};
36 };
37 
39 class NotFound : public Exception {
40 public:
41  NotFound(std::string msg = "NotFound") : Exception(msg){};
42 };
43 
45 class Error : public Exception {
46 public:
47  Error(std::string msg = "Error") : Exception(msg){};
48 };
49 
50 #define THROW_RETRIEVAL_EXC(retRes, objName) \
51  switch (retRes) { \
52  case RetrievalResult::NOTAVAILABLE: \
53  throw Retrieval::NotAvailable("Object \"" + objName + "\" is not available"); \
54  break; \
55  case RetrievalResult::BADCLASS: \
56  throw Retrieval::BadClass("Bad class for object \"" + objName + "\""); \
57  break; \
58  case RetrievalResult::NOTFOUND: \
59  throw Retrieval::NotFound("Object \"" + objName + "\" is not found"); \
60  break; \
61  case RetrievalResult::ERROR: \
62  throw Retrieval::Error("Error while retrieving object \"" + objName + "\""); \
63  break; \
64  default: \
65  throw EA::Exception("Invalid RetrievalResult in THROW_RETRIEVAL_EXC"); \
66  }
67 
68 static std::string ExcName(const Exception &exc) {
69  auto excName = Demangler::ClassName(exc);
70  // Remove EA::Retrieval:: from class name
71  excName = excName.substr(15);
72  return excName;
73 }
74 
75 } // namespace Retrieval
76 
77 } // namespace EA
78 
79 #endif /* RETRIEVALEXCEPTIONS_H_ */
Exception(std::string msg="Exception")
Definition: RetrievalExceptions.h:23
static std::string ExcName(const Exception &exc)
Definition: RetrievalExceptions.h:68
Exception for generic error in object retrieve procedure.
Definition: RetrievalExceptions.h:45
std::string ClassName(const T &obj)
Function which returns the name of the class.
Definition: Demangler.h:30
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
Base class for retrieval exceptions.
Definition: RetrievalExceptions.h:21
NotFound(std::string msg="NotFound")
Definition: RetrievalExceptions.h:41
Exception for unknown object.
Definition: RetrievalExceptions.h:39
Exception for object found but class does not match with requested.
Definition: RetrievalExceptions.h:33
Error(std::string msg="Error")
Definition: RetrievalExceptions.h:47
NotAvailable(std::string msg="NotAvailable")
Definition: RetrievalExceptions.h:29
Definition: Exception.h:24
Exception for known object but not available at the moment.
Definition: RetrievalExceptions.h:27
BadClass(std::string msg="BadClass")
Definition: RetrievalExceptions.h:35