| [0b990d] | 1 | 
 | 
|---|
 | 2 | #include <util/class/scexception.h>
 | 
|---|
 | 3 | #include <stdexcept>
 | 
|---|
 | 4 | 
 | 
|---|
 | 5 | using namespace sc;
 | 
|---|
 | 6 | 
 | 
|---|
 | 7 | class X: public DescribedClass {
 | 
|---|
 | 8 |   public:
 | 
|---|
 | 9 |     X() {};
 | 
|---|
 | 10 |     void x() {
 | 
|---|
 | 11 |       throw AlgorithmException("algorithm exception in X::x()",
 | 
|---|
 | 12 |                                __FILE__,
 | 
|---|
 | 13 |                                __LINE__,
 | 
|---|
 | 14 |                                this->class_desc());
 | 
|---|
 | 15 |     }
 | 
|---|
 | 16 | };
 | 
|---|
 | 17 | 
 | 
|---|
 | 18 | static ClassDesc X_cd(typeid(X),"X",1,"public DescribedClass");
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | class NestedException: public SCException {
 | 
|---|
 | 21 |   public:
 | 
|---|
 | 22 |     NestedException(
 | 
|---|
 | 23 |         const char *description = 0,
 | 
|---|
 | 24 |         const char *file = 0,
 | 
|---|
 | 25 |         int line = 0,
 | 
|---|
 | 26 |         const ClassDesc *class_desc = 0,
 | 
|---|
 | 27 |         const char *exception_type = "NestedException") throw():
 | 
|---|
 | 28 |       SCException(description, file, line, class_desc, exception_type)
 | 
|---|
 | 29 |         {
 | 
|---|
 | 30 |           try {
 | 
|---|
 | 31 |               if (description) throw NestedException();
 | 
|---|
 | 32 |               throw std::runtime_error("ctor");
 | 
|---|
 | 33 |             }
 | 
|---|
 | 34 |           catch (...) {}
 | 
|---|
 | 35 |         }
 | 
|---|
 | 36 |   
 | 
|---|
 | 37 |     NestedException(const NestedException& ref) throw():
 | 
|---|
 | 38 |       SCException(ref)
 | 
|---|
 | 39 |         {
 | 
|---|
 | 40 |           try {
 | 
|---|
 | 41 |               if (description()) throw NestedException();
 | 
|---|
 | 42 |               throw std::runtime_error("ctor");
 | 
|---|
 | 43 |             }
 | 
|---|
 | 44 |           catch (...) {}
 | 
|---|
 | 45 |         }
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 |     ~NestedException() throw()
 | 
|---|
 | 48 |         {
 | 
|---|
 | 49 |           try {
 | 
|---|
 | 50 |               if (description()) throw NestedException();
 | 
|---|
 | 51 |               throw std::runtime_error("ctor");
 | 
|---|
 | 52 |             }
 | 
|---|
 | 53 |           catch (...) {}
 | 
|---|
 | 54 |         }
 | 
|---|
 | 55 | };
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 | void
 | 
|---|
 | 58 | f()
 | 
|---|
 | 59 | {
 | 
|---|
 | 60 |   throw AlgorithmException("algorithm exception in f()",
 | 
|---|
 | 61 |                            __FILE__,
 | 
|---|
 | 62 |                            __LINE__
 | 
|---|
 | 63 |                            );
 | 
|---|
 | 64 | }
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | void
 | 
|---|
 | 67 | g()
 | 
|---|
 | 68 | {
 | 
|---|
 | 69 |   throw MaxIterExceeded("maxiter exception in g()",
 | 
|---|
 | 70 |                         __FILE__,
 | 
|---|
 | 71 |                         __LINE__,
 | 
|---|
 | 72 |                         10);
 | 
|---|
 | 73 | }
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | void
 | 
|---|
 | 76 | h()
 | 
|---|
 | 77 | {
 | 
|---|
 | 78 |   throw ToleranceExceeded("tolerance exception in g()",
 | 
|---|
 | 79 |                           __FILE__,
 | 
|---|
 | 80 |                           __LINE__,
 | 
|---|
 | 81 |                           1.0, 2.0);
 | 
|---|
 | 82 | }
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | void
 | 
|---|
 | 85 | i()
 | 
|---|
 | 86 | {
 | 
|---|
 | 87 |   throw SystemException("system exception in i()",
 | 
|---|
 | 88 |                            __FILE__,
 | 
|---|
 | 89 |                            __LINE__
 | 
|---|
 | 90 |                            );
 | 
|---|
 | 91 | }
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | void
 | 
|---|
 | 94 | j()
 | 
|---|
 | 95 | {
 | 
|---|
 | 96 |   throw MemAllocFailed("memalloc exception in j()",
 | 
|---|
 | 97 |                         __FILE__,
 | 
|---|
 | 98 |                         __LINE__,
 | 
|---|
 | 99 |                         100000);
 | 
|---|
 | 100 | }
 | 
|---|
 | 101 | 
 | 
|---|
 | 102 | void
 | 
|---|
 | 103 | k()
 | 
|---|
 | 104 | {
 | 
|---|
 | 105 |   throw ProgrammingError("programming error in k()",
 | 
|---|
 | 106 |                          __FILE__,
 | 
|---|
 | 107 |                          __LINE__);
 | 
|---|
 | 108 | }
 | 
|---|
 | 109 | 
 | 
|---|
 | 110 | void
 | 
|---|
 | 111 | l()
 | 
|---|
 | 112 | {
 | 
|---|
 | 113 |   throw InputError("input error in l()",
 | 
|---|
 | 114 |                    __FILE__,
 | 
|---|
 | 115 |                    __LINE__,
 | 
|---|
 | 116 |                    "the_keyword",
 | 
|---|
 | 117 |                    "the_value");
 | 
|---|
 | 118 | }
 | 
|---|
 | 119 | 
 | 
|---|
 | 120 | void
 | 
|---|
 | 121 | m()
 | 
|---|
 | 122 | {
 | 
|---|
 | 123 |   throw LimitExceeded<int>("limit exceeded in m()",
 | 
|---|
 | 124 |                            __FILE__,
 | 
|---|
 | 125 |                            __LINE__,
 | 
|---|
 | 126 |                            10, 11);
 | 
|---|
 | 127 | }
 | 
|---|
 | 128 | 
 | 
|---|
 | 129 | void
 | 
|---|
 | 130 | n()
 | 
|---|
 | 131 | {
 | 
|---|
 | 132 |   throw FileOperationFailed("file op failed in n()",
 | 
|---|
 | 133 |                             __FILE__,
 | 
|---|
 | 134 |                             __LINE__,
 | 
|---|
 | 135 |                             "outfile",
 | 
|---|
 | 136 |                             FileOperationFailed::OpenRW);
 | 
|---|
 | 137 | }
 | 
|---|
 | 138 | 
 | 
|---|
 | 139 | void
 | 
|---|
 | 140 | o()
 | 
|---|
 | 141 | {
 | 
|---|
 | 142 |   throw SyscallFailed("syscall failed in o()",
 | 
|---|
 | 143 |                       __FILE__,
 | 
|---|
 | 144 |                       __LINE__,
 | 
|---|
 | 145 |                       "xyz",
 | 
|---|
 | 146 |                       10);
 | 
|---|
 | 147 | }
 | 
|---|
 | 148 | 
 | 
|---|
 | 149 | void
 | 
|---|
 | 150 | p()
 | 
|---|
 | 151 | {
 | 
|---|
 | 152 |   throw FeatureNotImplemented("p() not implemented",
 | 
|---|
 | 153 |                               __FILE__,
 | 
|---|
 | 154 |                               __LINE__);
 | 
|---|
 | 155 | }
 | 
|---|
 | 156 | 
 | 
|---|
 | 157 | void
 | 
|---|
 | 158 | ex_on_stack()
 | 
|---|
 | 159 | {
 | 
|---|
 | 160 |   ProgrammingError ex("programming error in ex_on_stack()",
 | 
|---|
 | 161 |                       __FILE__, __LINE__);
 | 
|---|
 | 162 |   try {
 | 
|---|
 | 163 |       ex.elaborate() << "more info about the problem" << std::endl;
 | 
|---|
 | 164 |       throw std::runtime_error("whoops");
 | 
|---|
 | 165 |     }
 | 
|---|
 | 166 |   catch (...) {}
 | 
|---|
 | 167 |   throw ex;
 | 
|---|
 | 168 | }
 | 
|---|
 | 169 | 
 | 
|---|
 | 170 | void
 | 
|---|
 | 171 | nested()
 | 
|---|
 | 172 | {
 | 
|---|
 | 173 |   throw NestedException("nested exception test",
 | 
|---|
 | 174 |                         __FILE__, __LINE__);
 | 
|---|
 | 175 | }
 | 
|---|
 | 176 | 
 | 
|---|
 | 177 | main()
 | 
|---|
 | 178 | {
 | 
|---|
 | 179 |   try {
 | 
|---|
 | 180 |       f();
 | 
|---|
 | 181 |       std::cout << "ERROR: f() ran OK" << std::endl;
 | 
|---|
 | 182 |     }
 | 
|---|
 | 183 |   catch (SCException &e) {
 | 
|---|
 | 184 |       std::cout << "EXPECTED: got an f() exception" << std::endl;
 | 
|---|
 | 185 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 186 |     }
 | 
|---|
 | 187 | 
 | 
|---|
 | 188 |   try {
 | 
|---|
 | 189 |       g();
 | 
|---|
 | 190 |       std::cout << "ERROR: g() ran OK" << std::endl;
 | 
|---|
 | 191 |     }
 | 
|---|
 | 192 |   catch (SCException &e) {
 | 
|---|
 | 193 |       std::cout << "EXPECTED: got an g() exception" << std::endl;
 | 
|---|
 | 194 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 195 |     }
 | 
|---|
 | 196 | 
 | 
|---|
 | 197 |   try {
 | 
|---|
 | 198 |       h();
 | 
|---|
 | 199 |       std::cout << "ERROR: h() ran OK" << std::endl;
 | 
|---|
 | 200 |     }
 | 
|---|
 | 201 |   catch (SCException &e) {
 | 
|---|
 | 202 |       std::cout << "EXPECTED: got an h() exception" << std::endl;
 | 
|---|
 | 203 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 204 |     }
 | 
|---|
 | 205 | 
 | 
|---|
 | 206 |   try {
 | 
|---|
 | 207 |       i();
 | 
|---|
 | 208 |       std::cout << "ERROR: i() ran OK" << std::endl;
 | 
|---|
 | 209 |     }
 | 
|---|
 | 210 |   catch (SCException &e) {
 | 
|---|
 | 211 |       std::cout << "EXPECTED: got an i() exception" << std::endl;
 | 
|---|
 | 212 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 213 |     }
 | 
|---|
 | 214 | 
 | 
|---|
 | 215 |   try {
 | 
|---|
 | 216 |       j();
 | 
|---|
 | 217 |       std::cout << "ERROR: j() ran OK" << std::endl;
 | 
|---|
 | 218 |     }
 | 
|---|
 | 219 |   catch (SCException &e) {
 | 
|---|
 | 220 |       std::cout << "EXPECTED: got an j() exception" << std::endl;
 | 
|---|
 | 221 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 222 |     }
 | 
|---|
 | 223 | 
 | 
|---|
 | 224 |   try {
 | 
|---|
 | 225 |       k();
 | 
|---|
 | 226 |       std::cout << "ERROR: k() ran OK" << std::endl;
 | 
|---|
 | 227 |     }
 | 
|---|
 | 228 |   catch (SCException &e) {
 | 
|---|
 | 229 |       std::cout << "EXPECTED: got an k() exception" << std::endl;
 | 
|---|
 | 230 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 231 |     }
 | 
|---|
 | 232 | 
 | 
|---|
 | 233 |   try {
 | 
|---|
 | 234 |       l();
 | 
|---|
 | 235 |       std::cout << "ERROR: l() ran OK" << std::endl;
 | 
|---|
 | 236 |     }
 | 
|---|
 | 237 |   catch (SCException &e) {
 | 
|---|
 | 238 |       std::cout << "EXPECTED: got an l() exception" << std::endl;
 | 
|---|
 | 239 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 240 |     }
 | 
|---|
 | 241 | 
 | 
|---|
 | 242 |   try {
 | 
|---|
 | 243 |       m();
 | 
|---|
 | 244 |       std::cout << "ERROR: m() ran OK" << std::endl;
 | 
|---|
 | 245 |     }
 | 
|---|
 | 246 |   catch (SCException &e) {
 | 
|---|
 | 247 |       std::cout << "EXPECTED: got an m() exception" << std::endl;
 | 
|---|
 | 248 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 249 |     }
 | 
|---|
 | 250 | 
 | 
|---|
 | 251 |   try {
 | 
|---|
 | 252 |       n();
 | 
|---|
 | 253 |       std::cout << "ERROR: n() ran OK" << std::endl;
 | 
|---|
 | 254 |     }
 | 
|---|
 | 255 |   catch (SCException &e) {
 | 
|---|
 | 256 |       std::cout << "EXPECTED: got an n() exception" << std::endl;
 | 
|---|
 | 257 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 258 |     }
 | 
|---|
 | 259 | 
 | 
|---|
 | 260 |   try {
 | 
|---|
 | 261 |       o();
 | 
|---|
 | 262 |       std::cout << "ERROR: o() ran OK" << std::endl;
 | 
|---|
 | 263 |     }
 | 
|---|
 | 264 |   catch (SCException &e) {
 | 
|---|
 | 265 |       std::cout << "EXPECTED: got an o() exception" << std::endl;
 | 
|---|
 | 266 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 267 |     }
 | 
|---|
 | 268 | 
 | 
|---|
 | 269 |   try {
 | 
|---|
 | 270 |       p();
 | 
|---|
 | 271 |       std::cout << "ERROR: p() ran OK" << std::endl;
 | 
|---|
 | 272 |     }
 | 
|---|
 | 273 |   catch (SCException &e) {
 | 
|---|
 | 274 |       std::cout << "EXPECTED: got an p() exception" << std::endl;
 | 
|---|
 | 275 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 276 |     }
 | 
|---|
 | 277 | 
 | 
|---|
 | 278 |   try {
 | 
|---|
 | 279 |       X x;
 | 
|---|
 | 280 |       x.x();
 | 
|---|
 | 281 |       std::cout << "x.x() ran OK" << std::endl;
 | 
|---|
 | 282 |     }
 | 
|---|
 | 283 |   catch (SCException &e) {
 | 
|---|
 | 284 |       std::cout << "EXPECTED: got an x.x() exception" << std::endl;
 | 
|---|
 | 285 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 286 |     }
 | 
|---|
 | 287 | 
 | 
|---|
 | 288 |   try {
 | 
|---|
 | 289 |       ex_on_stack();
 | 
|---|
 | 290 |       std::cout << "ERROR: ex_on_stack() ran OK" << std::endl;
 | 
|---|
 | 291 |     }
 | 
|---|
 | 292 |   catch (SCException &e) {
 | 
|---|
 | 293 |       std::cout << "EXPECTED: got an ex_on_stack() exception" << std::endl;
 | 
|---|
 | 294 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 295 |     }
 | 
|---|
 | 296 | 
 | 
|---|
 | 297 |   try {
 | 
|---|
 | 298 |       nested();
 | 
|---|
 | 299 |       std::cout << "ERROR: nested() ran OK" << std::endl;
 | 
|---|
 | 300 |     }
 | 
|---|
 | 301 |   catch (SCException &e) {
 | 
|---|
 | 302 |       std::cout << "EXPECTED: got an nested() exception" << std::endl;
 | 
|---|
 | 303 |       std::cout << e.what() << std::endl;
 | 
|---|
 | 304 |     }
 | 
|---|
 | 305 | 
 | 
|---|
 | 306 |   return 0;
 | 
|---|
 | 307 | }
 | 
|---|
 | 308 | 
 | 
|---|