|
|
| version 1.7, 2001/03/11 08:16:32 | version 1.38.2.15, 2003/02/21 10:55:43 |
|---|---|
| Line 1 | Line 1 |
| /* | /** @file |
| Parser | Parser: exception decls. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | |
| $Id$ | 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$"; |
| #include "pa_types.h" | // includes |
| #include "pa_string.h" | |
| #include "pa_memory.h" | |
| // forwards | |
| class String; DECLARE_OBJECT_PTR(String); | |
| // defines | |
| class Exception { | class Exception { |
| public: | public: |
| // address for long jump to jump to | static const char* undefined_type; |
| // regretfully public: | static const StringPtr undefined_source; |
| // can't make local unless sure of inlining | |
| // for to-die stack frame ruins it all | Exception(); |
| mutable jmp_buf mark; | Exception( |
| const char* atype, | |
| void _throw( | StringPtr aproblem_source, |
| const String *atype, const String *acode, | const char* comment_fmt, ...); |
| const String *aproblem_source, | Exception(const Exception& src); |
| const char *comment_fmt, ...) const; | Exception& operator =(const Exception& src); |
| const String *type() const { return ftype; } | #ifdef XML |
| const String *code() const { return fcode; } | Exception( |
| const String *problem_source() const { return fproblem_source; } | StringPtr aproblem_source, |
| const char *comment() const { return fcomment[0]?fcomment:0; } | GdomeException& exc); |
| #endif | |
| /// extracts exception type | |
| const char* type(bool can_be_empty=false) const { | |
| if(can_be_empty) | |
| return ftype; | |
| else | |
| return ftype?ftype:"<no type>"; | |
| } | |
| /// extracts exception problem_source | |
| StringPtr 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: |
| mutable const String *ftype, *fcode, *fproblem_source; | const char* ftype; |
| mutable char fcomment[MAX_STRING]; | StringPtr fproblem_source; |
| }; | CharPtr fcomment; |
| //#define EXCEPTION_TRY(e) (setjmp((e).mark)==0) | }; |
| // usage: | |
| // if(EXCEPTION_TRY(e)) { ...; if(?) e.raise(?); ...; } else { catch-code } | |
| #endif | #endif |