Annotation of parser3/src/include/pa_exception.h, revision 1.73
1.10 paf 1: /** @file
1.11 paf 2: Parser: exception decls.
3:
1.70 moko 4: Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com)
1.69 moko 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1 paf 6: */
7:
8: #ifndef PA_EXCEPTION_H
9: #define PA_EXCEPTION_H
1.36 paf 10:
1.73 ! moko 11: #define IDENT_PA_EXCEPTION_H "$Id: pa_exception.h,v 1.72 2024/12/06 23:20:04 moko Exp $"
1.46 misha 12:
1.47 misha 13: const char* const PARSER_RUNTIME = "parser.runtime";
1.52 misha 14: const char* const IMAGE_FORMAT = "image.format";
1.53 misha 15: const char* const PCRE_EXCEPTION_TYPE = "pcre.execute";
1.54 misha 16: const char* const DATE_RANGE_EXCEPTION_TYPE = "date.range";
1.61 misha 17: const char* const BASE64_FORMAT = "base64.format";
1.1 paf 18:
1.48 misha 19: const char* const NAME_MUST_BE_STRING = "name must be string";
20: const char* const FILE_NAME_MUST_BE_STRING = "file name must be string";
1.73 ! moko 21: const char* const FILE_NAME_MUST_BE_STRING_OR_FILE = "file name must be string or file";
1.72 moko 22: const char* const FILE_NAME_MUST_BE_NE_STRING = "file name must be not empty string";
1.48 misha 23: const char* const VALUE_MUST_BE_STRING = "value must be string";
1.49 misha 24: const char* const PARAMETER_MUST_BE_STRING = "parameter must be string";
1.50 misha 25: const char* const COLUMN_NAME_MUST_BE_STRING = "column name must be string";
1.48 misha 26:
1.60 misha 27: const char* const FILE_NAME_MUST_BE_SPECIFIED = "file name must be specified";
1.51 misha 28: const char* const FIRST_ARG_MUST_NOT_BE_CODE = "first argument must not be code";
29: const char* const PARAM_MUST_NOT_BE_CODE = "param must not be code";
1.59 misha 30: const char* const PARAM_MUST_BE_HASH = "param must be hash";
1.51 misha 31: const char* const MODE_MUST_NOT_BE_CODE = "mode must not be code";
1.55 misha 32: const char* const OPTIONS_MUST_NOT_BE_CODE = "options must not be code";
1.48 misha 33:
1.57 misha 34: const char* const CALLED_WITH_INVALID_OPTION = "called with invalid option";
1.56 misha 35:
1.39 paf 36: // includes
1.14 parser 37:
1.39 paf 38: #include "pa_memory.h"
39:
40: // forwards
41:
42: class String;
1.14 parser 43:
1.22 paf 44: // defines
45:
1.1 paf 46: class Exception {
47: public:
48:
1.19 paf 49: Exception();
1.67 moko 50: Exception(const char* atype, const String* aproblem_source, const char* comment_fmt, ...);
1.22 paf 51: Exception(const Exception& src);
1.67 moko 52:
1.44 paf 53: operator bool() { return ftype || fproblem_source || fcomment; }
1.22 paf 54: Exception& operator =(const Exception& src);
1.1 paf 55:
1.10 paf 56: /// extracts exception type
1.67 moko 57: const char* type(bool can_be_empty=false) const {
58: return can_be_empty || ftype ? ftype : "<no type>";
1.35 paf 59: }
1.67 moko 60:
1.10 paf 61: /// extracts exception problem_source
1.39 paf 62: const String* problem_source() const;
1.67 moko 63:
1.10 paf 64: /// extracts exception comment
1.67 moko 65: const char* comment(bool can_be_empty=false) const {
66: const char* result=fcomment && *fcomment ? fcomment : 0;
67: return can_be_empty || result ? result : "<no comment>";
68: }
69:
70: // modifies exception to fine-tune error reporting
71: void set_source(const String* aproblem_source) {
72: if(!problem_source())
73: fproblem_source=aproblem_source;
74: }
75:
76: void add_comment(const char* acomment);
77:
78: #define ALTER_EXCEPTION_SOURCE(code, source) \
79: try { \
80: code; \
81: } catch (Exception& e) { \
82: e.set_source(source); \
83: rethrow; \
84: }
85:
86: #define ALTER_EXCEPTION_COMMENT(code, comment) \
87: try { \
88: code; \
89: } catch (Exception& e) { \
90: e.add_comment(comment); \
91: rethrow; \
1.35 paf 92: }
1.1 paf 93:
1.40 paf 94: protected:
1.1 paf 95:
1.39 paf 96: const char* ftype;
97: const String* fproblem_source;
1.64 moko 98: const char* fcomment;
1.15 parser 99:
1.1 paf 100: };
101:
102: #endif
E-mail: