EventAnalysis  1.0.0
InsertionExceptions.h
Go to the documentation of this file.
1 /*
2  * InsertionExceptions.h
3  *
4  * Created on: 23 Aug 2020
5  * Author: Nicola Mori
6  */
7 
8 #ifndef INSERTIONEXCEPTIONS_H_
9 #define INSERTIONEXCEPTIONS_H_
10 
11 #include "core/Exception.h"
12 #include "core/InsertionResult.h"
13 
14 #include "utils/Demangler.h"
15 
16 namespace EA {
17 
18 namespace Insertion {
19 
21 class Exception : public EA::Exception {
22 public:
23  Exception(std::string msg = "Exception") : EA::Exception(msg){};
24 };
25 
27 class Duplicate : public Exception {
28 public:
29  Duplicate(std::string msg = "Duplicate") : Exception(msg){};
30 };
31 
33 class NameAliasClash : public Exception {
34 public:
35  NameAliasClash(std::string msg = "NameAliasClash") : Exception(msg){};
36 };
37 
39 class BadAliasedType : public Exception {
40 public:
41  BadAliasedType(std::string msg = "BadAliasedType") : Exception(msg){};
42 };
43 
46 public:
47  MissingAliasedObject(std::string msg = "MissingAliasedObject") : Exception(msg){};
48 };
49 
51 class AliasOfAlias : public Exception {
52 public:
53  AliasOfAlias(std::string msg = "AliasOfAlias") : Exception(msg){};
54 };
55 
57 class Error : public Exception {
58 public:
59  Error(std::string msg = "Error") : Exception(msg){};
60 };
61 
62 #define THROW_INSERTION_EXC(insRes, objName) \
63  switch (insRes) { \
64  case InsertionResult::DUPLICATE: \
65  throw Insertion::Duplicate("Object \"" + objName + "\" is already present in the data store"); \
66  break; \
67  case InsertionResult::NAMEALIASCLASH: \
68  throw Insertion::NameAliasClash("Clash with existing alias for object \"" + objName + "\""); \
69  break; \
70  case InsertionResult::ERROR: \
71  throw Insertion::Error("Error while inserting object \"" + objName + "\" in the data store"); \
72  break; \
73  default: \
74  throw EA::Exception("Invalid InsertionResult in THROW_INSERTION_EXC"); \
75  }
76 
77 #define THROW_ALIASING_EXC(insRes, objName, alias) \
78  switch (insRes) { \
79  case InsertionResult::NAMEALIASCLASH: \
80  throw Insertion::NameAliasClash("Clash with existing object for alias \"" + alias + "\""); \
81  break; \
82  case InsertionResult::BADALIASEDTYPE: \
83  throw Insertion::BadAliasedType("Wrong type for object" + objName + "\", can't move the alias \"" + alias + \
84  "\" to it"); \
85  break; \
86  case InsertionResult::MISSINGALIASEDOBJECT: \
87  throw Insertion::MissingAliasedObject( \
88  "Object \"" + objName + "\" is not present in the data store, can't set the alias \"" + alias + "\" for it"); \
89  break; \
90  case InsertionResult::ALIASOFALIAS: \
91  throw Insertion::AliasOfAlias("Object name \"" + objName + "\" is actually an alias, can't set an alias for it"); \
92  break; \
93  case InsertionResult::ERROR: \
94  throw Insertion::Error("Error while setting alias \"" + objName + "\""); \
95  break; \
96  default: \
97  throw EA::Exception("Invalid InsertionResult in THROW_ALIASING_EXC"); \
98  }
99 
100 static std::string ExcName(const Exception &exc) {
101  auto excName = Demangler::ClassName(exc);
102  // Remove EA::Insertion:: from class name
103  excName = excName.substr(15);
104  return excName;
105 }
106 
107 } // namespace Insertion
108 
109 } // namespace EA
110 
111 #endif /* INSERTIONEXCEPTIONS_H_ */
Duplicate(std::string msg="Duplicate")
Definition: InsertionExceptions.h:29
Exception for trying to insert a duplicate element.
Definition: InsertionExceptions.h:27
Exception for trying to assign an alias to an object that does not exist.
Definition: InsertionExceptions.h:45
AliasOfAlias(std::string msg="AliasOfAlias")
Definition: InsertionExceptions.h:53
Exception for trying to insert an object with a name clash with an existing alias and vice versa...
Definition: InsertionExceptions.h:33
static std::string ClassName()
Static method which returns the name of the class.
Definition: Demangler.h:46
static std::string ExcName(const Exception &exc)
Definition: InsertionExceptions.h:100
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
Exception for generic error in object insertion procedure.
Definition: InsertionExceptions.h:57
Exception for trying to assign an alias to an alias.
Definition: InsertionExceptions.h:51
Base class for insertion exceptions.
Definition: InsertionExceptions.h:21
MissingAliasedObject(std::string msg="MissingAliasedObject")
Definition: InsertionExceptions.h:47
Exception(std::string msg="Exception")
Definition: InsertionExceptions.h:23
Error(std::string msg="Error")
Definition: InsertionExceptions.h:59
NameAliasClash(std::string msg="NameAliasClash")
Definition: InsertionExceptions.h:35
Definition: Exception.h:24
BadAliasedType(std::string msg="BadAliasedType")
Definition: InsertionExceptions.h:41
Exception for trying to re-assign an alias to an object with a different class.
Definition: InsertionExceptions.h:39