|
|
| version 1.3, 2001/01/30 13:43:42 | version 1.38.2.11, 2003/01/29 13:52:21 |
|---|---|
| Line 1 | Line 1 |
| /* | /** @file |
| $Id$ | Parser: exception decls. |
| Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) | |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | |
| */ | */ |
| #ifndef PA_EXCEPTION_H | #ifndef PA_EXCEPTION_H |
| #define PA_EXCEPTION_H | #define PA_EXCEPTION_H |
| #include <setjmp.h> | static const char* IDENT_EXCEPTION_H="$Date$"; |
| // includes | |
| #include "pa_pool.h" | |
| // forwards | |
| class String; typedef object_ptr<const String> ConstStringPtr; | |
| #include "pa_types.h" | // defines |
| #include "pa_string.h" | |
| class Exception { | class Exception { |
| public: | public: |
| // address for long jump to jump to | static const char *undefined_type; |
| // regretfully public: | static const ConstStringPtr undefined_source; |
| // can't make local unless sure of inlining | |
| // for to-die stack frame ruins it all | Exception(); |
| jmp_buf mark; | Exception( |
| const char *atype, | |
| void raise( | ConstStringPtr aproblem_source, |
| const String *atype, const String *acode, | |
| const String *aproblem_source, | |
| const char *comment_fmt, ...); | const char *comment_fmt, ...); |
| Exception(const Exception& src): | |
| ftype(src.ftype), | |
| fproblem_source(src.fproblem_source), | |
| fcomment(src.fcomment) { | |
| } | |
| Exception& operator =(const Exception& src) { | |
| ftype=src.ftype; | |
| fproblem_source=src.fproblem_source; | |
| fcomment=src.fcomment; | |
| return *this; | |
| } | |
| #ifdef XML | |
| Exception( | |
| ConstStringPtr aproblem_source, | |
| GdomeException& exc); | |
| #endif | |
| const String *type() { return ftype; } | /// extracts exception type |
| const String *code() { return fcode; } | const char *type(bool can_be_empty=false) const { |
| const String *problem_source() { return fproblem_source; } | if(can_be_empty) |
| const char *comment() { return fcomment[0]?fcomment:0; } | return ftype; |
| else | |
| return ftype?ftype:"<no type>"; | |
| } | |
| /// extracts exception problem_source | |
| ConstStringPtr problem_source() const; /// extracts exception comment | |
| const char *comment(bool can_be_empty=false) const { | |
| const char *result=fcomment.get()!=0 && *fcomment.get()?fcomment.get():0; | |
| if(can_be_empty) | |
| return result; | |
| else | |
| return result?result:"<no comment>"; | |
| } | |
| private: | private: |
| const String *ftype, *fcode, *fproblem_source; | const char *ftype; |
| char fcomment[MAX_STRING]; | ConstStringPtr fproblem_source; |
| }; | CharPtr fcomment; |
| // usage: | }; |
| // if(EXCEPTION_TRY(e)) { ...; if(?) e.raise(?); ...; } else { catch-code } | |
| #define EXCEPTION_TRY(e) (setjmp((e).mark)==0) | |
| #endif | #endif |