Checked for more usual realife error cascade situation
This commit is contained in:
parent
c2cdfe7052
commit
3ac76f1fac
@ -8,6 +8,14 @@
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
|
||||
#ifndef THROW
|
||||
#ifdef CODE_ERROR_LOCATIONS
|
||||
#define THROW(type, ...) throw type(__VA_ARGS__, __LINE__, __FILE__)
|
||||
#else
|
||||
#define THROW(type, ...) throw type(__VA_ARGS__)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace nb {
|
||||
|
||||
typedef std::unordered_map<unsigned int, const char*> ErrorCodeMap;
|
||||
@ -98,8 +106,8 @@ public:
|
||||
};
|
||||
|
||||
Error(unsigned int code) : ErrorBase<Error>(code, ErrorBase<Error>::lookup(code)) {}
|
||||
Error(unsigned int code, const std::exception& trace)
|
||||
: ErrorBase<Error>(code, ErrorBase<Error>::lookup(code), trace) {}
|
||||
Error(unsigned int code, const std::exception& trace, unsigned int line=0, const std::string& filename="")
|
||||
: ErrorBase<Error>(code, ErrorBase<Error>::lookup(code), trace, line, filename) {}
|
||||
|
||||
friend ErrorBase<Error>;
|
||||
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
#define CODE_ERROR_LOCATIONS
|
||||
|
||||
#include "Errors.hpp"
|
||||
#include <iostream>
|
||||
|
||||
@ -5,10 +7,10 @@ using namespace nb;
|
||||
|
||||
class TestError : public ErrorBase<TestError> {
|
||||
public:
|
||||
TestError(unsigned int code)
|
||||
TestError(unsigned int code, unsigned int line=0, const std::string& filename="")
|
||||
: ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code)) {}
|
||||
TestError(unsigned int code, const std::exception& trace)
|
||||
: ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code), trace) {}
|
||||
TestError(unsigned int code, const std::exception& trace, unsigned int line=0, const std::string& filename="")
|
||||
: ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code), trace, line, filename) {}
|
||||
|
||||
enum ErrorCodes : unsigned int {
|
||||
A, B, C, D
|
||||
@ -26,11 +28,28 @@ const ErrorCodeMap TestError::ErrorMessages{
|
||||
};
|
||||
|
||||
int main() {
|
||||
TestError d(TestError::ErrorCodes::D, std::out_of_range("hey"));
|
||||
TestError c(TestError::ErrorCodes::C, d);
|
||||
TestError b(TestError::ErrorCodes::B, c);
|
||||
TestError a(TestError::ErrorCodes::A, b);
|
||||
throw Error(Error::ErrorCodes::UNDEFINED, a);
|
||||
//TestError d(TestError::ErrorCodes::D, std::out_of_range("hey"));
|
||||
//TestError c(TestError::ErrorCodes::C, d);
|
||||
//TestError b(TestError::ErrorCodes::B, c);
|
||||
//TestError a(TestError::ErrorCodes::A, b);
|
||||
//throw Error(Error::ErrorCodes::UNDEFINED, a);
|
||||
try {
|
||||
try {
|
||||
try {
|
||||
try {
|
||||
THROW(TestError, TestError::ErrorCodes::D);
|
||||
} catch (const std::exception& e){
|
||||
THROW(TestError, TestError::ErrorCodes::C, e);
|
||||
}
|
||||
} catch(const std::exception& e) {
|
||||
THROW(TestError, TestError::ErrorCodes::B, e);
|
||||
}
|
||||
} catch(const std::exception& e) {
|
||||
THROW(TestError, TestError::ErrorCodes::A, e);
|
||||
}
|
||||
} catch(const std::exception& e) {
|
||||
THROW(Error, Error::ErrorCodes::UNDEFINED, e);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user