--- parser3/src/main/pa_exception.C 2001/10/19 14:15:23 1.20 +++ parser3/src/main/pa_exception.C 2001/11/15 20:26:34 1.26 @@ -2,14 +2,18 @@ Parser: exception class. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: pa_exception.C,v 1.20 2001/10/19 14:15:23 parser Exp $ + $Id: pa_exception.C,v 1.26 2001/11/15 20:26:34 paf Exp $ */ #include "pa_common.h" #include "pa_exception.h" +Exception::Exception() { + ftype=fcode=fproblem_source=0; + owns_comment=false; fcomment=0; +} Exception::Exception(const String *atype, const String *acode, const String *aproblem_source, const char *comment_fmt, ...) { @@ -17,18 +21,46 @@ Exception::Exception(const String *atype ftype=atype; fcode=acode; fproblem_source=aproblem_source; + owns_comment=true; if(comment_fmt) { va_list args; va_start(args, comment_fmt); + fcomment=(char *)malloc(MAX_STRING); vsnprintf(fcomment, MAX_STRING, comment_fmt, args); va_end(args); - } else - fcomment[0]=0; + } else + fcomment=0; +} +Exception::Exception(const Exception& src) : + ftype(src.ftype), + fcode(src.fcode), + fproblem_source(src.fproblem_source), + fcomment(src.fcomment), + owns_comment(src.owns_comment) { + // that ugly string got from STL, along with principal ideal + const_cast(&src)->owns_comment=false; +} +Exception& Exception::operator =(const Exception& src) { + ftype=src.ftype; + fcode=src.fcode; + fproblem_source=src.fproblem_source; + + if(owns_comment) + free(fcomment); + fcomment=src.fcomment; + // that ugly string got from STL, along with principal ideal + owns_comment=src.owns_comment; ((Exception*)&src)->owns_comment=false; + + return *this; +} +Exception::~Exception() { + if(owns_comment) + free(fcomment); } #ifdef XML -void Exception::convert(Pool& pool, const String *source, const XSLException& e) { +void Exception::provide_source(Pool& pool, const String *source, const XSLException& e) { if(e.getURI().empty()) throw Exception(0, 0, source, @@ -49,14 +81,14 @@ void Exception::convert(Pool& pool, cons ); } -void Exception::convert(Pool& pool, const String *source, const SAXException& e) { +void Exception::provide_source(Pool& pool, const String *source, const SAXException& e) { throw Exception(0, 0, source, "%s", pool.transcode_cstr(XalanDOMString(e.getMessage())) // message for exception ); } -void Exception::convert(Pool& pool, const String *source, const SAXParseException& e) { +void Exception::provide_source(Pool& pool, const String *source, const SAXParseException& e) { throw Exception(0, 0, source, "%s. %s(%d:%d)", @@ -67,7 +99,7 @@ void Exception::convert(Pool& pool, cons } -void Exception::convert(Pool& pool, const String *source, const XMLException& e) { +void Exception::provide_source(Pool& pool, const String *source, const XMLException& e) { throw Exception(0, 0, source, "%s (%s). %s(%d)'", @@ -80,7 +112,7 @@ void Exception::convert(Pool& pool, cons ); } -void Exception::convert(Pool& pool, const String *source, const XalanDOMException& e) { +void Exception::provide_source(Pool& pool, const String *source, const XalanDOMException& e) { const char *s; int code=(int)e.getExceptionCode(); switch(code) {