cvc4-1.4
exception.h
Go to the documentation of this file.
1/********************* */
17#include "cvc4_public.h"
18
19#ifndef __CVC4__EXCEPTION_H
20#define __CVC4__EXCEPTION_H
21
22#include <iostream>
23#include <string>
24#include <sstream>
25#include <stdexcept>
26#include <exception>
27#include <cstdlib>
28#include <cstdarg>
29
30namespace CVC4 {
31
32class CVC4_PUBLIC Exception : public std::exception {
33protected:
34 std::string d_msg;
35
36public:
37 // Constructors
38 Exception() throw() : d_msg("Unknown exception") {}
39 Exception(const std::string& msg) throw() : d_msg(msg) {}
40 Exception(const char* msg) throw() : d_msg(msg) {}
41
42 // Destructor
43 virtual ~Exception() throw() {}
44
45 // NON-VIRTUAL METHOD for setting and printing the error message
46 void setMessage(const std::string& msg) throw() { d_msg = msg; }
47 std::string getMessage() const throw() { return d_msg; }
48
49 // overridden from base class std::exception
50 virtual const char* what() const throw() { return d_msg.c_str(); }
51
64 std::string toString() const throw() {
65 std::stringstream ss;
66 toStream(ss);
67 return ss.str();
68 }
69
75 virtual void toStream(std::ostream& os) const throw() { os << d_msg; }
76
77};/* class Exception */
78
80protected:
82
83 void construct(const char* header, const char* extra,
84 const char* function, const char* fmt, ...) {
85 va_list args;
86 va_start(args, fmt);
87 construct(header, extra, function, fmt, args);
88 va_end(args);
89 }
90
91 void construct(const char* header, const char* extra,
92 const char* function, const char* fmt, va_list args);
93
94 void construct(const char* header, const char* extra,
95 const char* function);
96
97public:
98 IllegalArgumentException(const char* condStr, const char* argDesc,
99 const char* function, const char* fmt, ...) :
100 Exception() {
101 va_list args;
102 va_start(args, fmt);
103 construct("Illegal argument detected",
104 ( std::string("`") + argDesc + "' is a bad argument"
105 + (*condStr == '\0' ? std::string() :
106 ( std::string("; expected ") +
107 condStr + " to hold" )) ).c_str(),
108 function, fmt, args);
109 va_end(args);
110 }
111
112 IllegalArgumentException(const char* condStr, const char* argDesc,
113 const char* function) :
114 Exception() {
115 construct("Illegal argument detected",
116 ( std::string("`") + argDesc + "' is a bad argument"
117 + (*condStr == '\0' ? std::string() :
118 ( std::string("; expected ") +
119 condStr + " to hold" )) ).c_str(),
120 function);
121 }
122};/* class IllegalArgumentException */
123
124inline std::ostream& operator<<(std::ostream& os, const Exception& e) throw() CVC4_PUBLIC;
125inline std::ostream& operator<<(std::ostream& os, const Exception& e) throw() {
126 e.toStream(os);
127 return os;
128}
129
130}/* CVC4 namespace */
131
132#if (defined(__BUILDING_CVC4LIB) || defined(__BUILDING_CVC4LIB_UNIT_TEST)) && !defined(__BUILDING_STATISTICS_FOR_EXPORT)
133# include "util/cvc4_assert.h"
134#endif /* (__BUILDING_CVC4LIB || __BUILDING_CVC4LIB_UNIT_TEST) && !__BUILDING_STATISTICS_FOR_EXPORT */
135
136namespace CVC4 {
137
138#ifndef CheckArgument
139template <class T> inline void CheckArgument(bool cond, const T& arg, const char* fmt, ...) CVC4_PUBLIC;
140template <class T> inline void CheckArgument(bool cond, const T& arg, const char* fmt, ...) {
141 if(__builtin_expect( ( !cond ), false )) { \
142 throw ::CVC4::IllegalArgumentException("", "", ""); \
143 } \
144}
145template <class T> inline void CheckArgument(bool cond, const T& arg) CVC4_PUBLIC;
146template <class T> inline void CheckArgument(bool cond, const T& arg) {
147 if(__builtin_expect( ( !cond ), false )) { \
148 throw ::CVC4::IllegalArgumentException("", "", ""); \
149 } \
150}
151#endif /* CheckArgument */
152
153#ifndef DebugCheckArgument
154template <class T> inline void DebugCheckArgument(bool cond, const T& arg, const char* fmt, ...) CVC4_PUBLIC;
155template <class T> inline void DebugCheckArgument(bool cond, const T& arg, const char* fmt, ...) {
156 if(__builtin_expect( ( !cond ), false )) { \
157 throw ::CVC4::IllegalArgumentException("", "", ""); \
158 } \
159}
160template <class T> inline void DebugCheckArgument(bool cond, const T& arg) CVC4_PUBLIC;
161template <class T> inline void DebugCheckArgument(bool cond, const T& arg) {
162 if(__builtin_expect( ( !cond ), false )) { \
163 throw ::CVC4::IllegalArgumentException("", "", ""); \
164 } \
165}
166#endif /* DebugCheckArgument */
167
168}/* CVC4 namespace */
169
170#endif /* __CVC4__EXCEPTION_H */
std::string toString() const
Get this exception as a string.
Definition exception.h:64
virtual const char * what() const
Definition exception.h:50
void setMessage(const std::string &msg)
Definition exception.h:46
std::string d_msg
Definition exception.h:34
virtual void toStream(std::ostream &os) const
Printing: feel free to redefine toStream().
Definition exception.h:75
Exception(const std::string &msg)
Definition exception.h:39
Exception(const char *msg)
Definition exception.h:40
std::string getMessage() const
Definition exception.h:47
virtual ~Exception()
Definition exception.h:43
void construct(const char *header, const char *extra, const char *function, const char *fmt, va_list args)
IllegalArgumentException(const char *condStr, const char *argDesc, const char *function)
Definition exception.h:112
IllegalArgumentException(const char *condStr, const char *argDesc, const char *function, const char *fmt,...)
Definition exception.h:98
void construct(const char *header, const char *extra, const char *function)
void construct(const char *header, const char *extra, const char *function, const char *fmt,...)
Definition exception.h:83
Macros that should be defined everywhere during the building of the libraries and driver binary,...
#define CVC4_PUBLIC
Definition cvc4_public.h:30
Definition expr.h:106
void DebugCheckArgument(bool cond, const T &arg, const char *fmt,...)
Definition exception.h:155
std::ostream & operator<<(std::ostream &out, const TypeCheckingException &e)
void CheckArgument(bool cond, const T &arg, const char *fmt,...)
Definition exception.h:140