|
|
| version 1.51, 2013/07/16 15:06:40 | version 1.63, 2024/11/04 03:53:25 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: exception class. | Parser: exception class. |
| Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru> |
| */ | */ |
| #include "pa_common.h" | #include "pa_common.h" |
| Line 15 volatile const char * IDENT_PA_EXCEPTION | Line 15 volatile const char * IDENT_PA_EXCEPTION |
| // methods | // methods |
| Exception::Exception(): ftype(0), fproblem_source(0), fcomment(0) {} | Exception::Exception(): ftype(0), fproblem_source(0), fcomment(0) {} |
| Exception::Exception(const Exception& src): | Exception::Exception(const Exception& src): |
| ftype(src.ftype), | ftype(src.ftype), |
| fproblem_source(src.fproblem_source), | fproblem_source(src.fproblem_source), |
| fcomment(src.fcomment) { | fcomment(src.fcomment) { |
| } | } |
| Exception& Exception::operator =(const Exception& src) { | Exception& Exception::operator =(const Exception& src) { |
| ftype=src.ftype; | ftype=src.ftype; |
| fproblem_source=src.fproblem_source; | fproblem_source=src.fproblem_source; |
| Line 27 Exception& Exception::operator =(const E | Line 29 Exception& Exception::operator =(const E |
| return *this; | return *this; |
| } | } |
| Exception::Exception(const char* atype, | Exception::Exception(const char* atype, const String* aproblem_source, const char* comment_fmt, ...) { |
| const String* aproblem_source, | |
| const char* comment_fmt, ...) { | |
| ftype=atype; | ftype=atype; |
| fproblem_source=aproblem_source; | fproblem_source=aproblem_source ? new String(*aproblem_source) : 0; |
| if(comment_fmt) { | if(!comment_fmt) { |
| fcomment=new(PointerFreeGC) char[MAX_STRING]; | fcomment=0; |
| } else if (!strcmp(comment_fmt, "%s")) { // to avoid MAX_STRING limit | |
| va_list args; | va_list args; |
| va_start(args, comment_fmt); | va_start(args, comment_fmt); |
| vsnprintf((char *)fcomment, MAX_STRING, comment_fmt, args); | fcomment=va_arg(args, const char *); |
| fcomment=fcomment ? pa_strdup(fcomment) : 0; | |
| va_end(args); | va_end(args); |
| } else | } else { |
| fcomment=0; | char comment[MAX_STRING]; |
| va_list args; | |
| va_start(args, comment_fmt); | |
| fcomment=pa_strdup(comment, vsnprintf(comment, MAX_STRING, comment_fmt, args)); | |
| va_end(args); | |
| } | |
| } | |
| void Exception::add_comment(const char* acomment) { | |
| if(acomment) | |
| fcomment=pa_strcat(fcomment, acomment); | |
| } | } |
| const String* Exception::problem_source() const { | const String* Exception::problem_source() const { |
| return fproblem_source && !fproblem_source->is_empty()?fproblem_source:0; | return fproblem_source && !fproblem_source->is_empty() ? fproblem_source : 0; |
| } | } |