--- parser3/src/main/pa_exception.C 2002/01/23 10:38:18 1.34 +++ parser3/src/main/pa_exception.C 2021/11/09 23:27:54 1.59 @@ -1,119 +1,60 @@ /** @file Parser: exception class. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://paf.design.ru) - - $Id: pa_exception.C,v 1.34 2002/01/23 10:38:18 paf Exp $ + Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) */ #include "pa_common.h" #include "pa_exception.h" +#include "pa_sapi.h" #include "pa_globals.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, ...) { - //_asm int 3; -//__asm__("int3"); - ftype=atype; - fcode=acode; - fproblem_source=aproblem_source; - owns_comment=true; +volatile const char * IDENT_PA_EXCEPTION_C="$Id: pa_exception.C,v 1.59 2021/11/09 23:27:54 moko Exp $" IDENT_PA_EXCEPTION_H; - if(comment_fmt) { - fcomment=(char *)malloc(MAX_STRING); - va_list args; - va_start(args, comment_fmt); - vsnprintf(fcomment, MAX_STRING, comment_fmt, args); - va_end(args); - } else - fcomment=0; -} -Exception::Exception(const Exception& src) : +// methods + +Exception::Exception(): ftype(0), fproblem_source(0), 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; + fcomment(src.fcomment) { } + 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 -Exception::Exception( - const String *atype, const String *acode, - const String *aproblem_source, - GdomeException& exc) : - ftype(atype), - fcode(acode), - fproblem_source(aproblem_source), - owns_comment(true) { - - const char *xml_generic_errors=xmlGenericErrors(); - if(xml_generic_errors || exc) { - const char *s; - switch((GdomeExceptionCode)exc) { - case GDOME_NOEXCEPTION_ERR: s="NOEXCEPTION_ERR"; break; - case GDOME_INDEX_SIZE_ERR: s="INDEX_SIZE_ERR"; break; - case GDOME_DOMSTRING_SIZE_ERR: s="DOMSTRING_SIZE_ERR"; break; - case GDOME_HIERARCHY_REQUEST_ERR: s="HIERARCHY_REQUEST_ERR"; break; - case GDOME_WRONG_DOCUMENT_ERR: s="WRONG_DOCUMENT_ERR"; break; - case GDOME_INVALID_CHARACTER_ERR: s="INVALID_CHARACTER_ERR"; break; - case GDOME_NO_DATA_ALLOWED_ERR: s="NO_DATA_ALLOWED_ERR"; break; - case GDOME_NO_MODIFICATION_ALLOWED_ERR: s="NO_MODIFICATION_ALLOWED_ERR"; break; - case GDOME_NOT_FOUND_ERR: s="NOT_FOUND_ERR"; break; - case GDOME_NOT_SUPPORTED_ERR: s="NOT_SUPPORTED_ERR"; break; - case GDOME_INUSE_ATTRIBUTE_ERR: s="INUSE_ATTRIBUTE_ERR"; break; - case GDOME_INVALID_STATE_ERR: s="INVALID_STATE_ERR"; break; - case GDOME_SYNTAX_ERR: s="SYNTAX_ERR"; break; - case GDOME_INVALID_MODIFICATION_ERR: s="INVALID_MODIFICATION_ERR"; break; - case GDOME_NAMESPACE_ERR: s="NAMESPACE_ERR"; break; - case GDOME_INVALID_ACCESS_ERR: s="INVALID_ACCESS_ERR"; break; - case GDOME_NULL_POINTER_ERR: s="NULL_POINTER_ERR"; break; - default: s=""; break; - } - - fcomment=(char *)malloc(MAX_STRING); - const char *xml_error_message= - xml_generic_errors?xml_generic_errors:""; - if(exc) - snprintf(fcomment, MAX_STRING, - "DOMException %s (%d).\n" - "%s", - s, // decoded code of exception - exc, // DOM exception code - xml_error_message // xml generic messages accumulated - ); - else // no DOM exception - snprintf(fcomment, MAX_STRING, - "%s", - xml_error_message // xml generic messages accumulated - ); - if(xml_generic_errors) - free((void *)xml_generic_errors); - } else +Exception::Exception(const char* atype, const String* aproblem_source, const char* comment_fmt, ...) { + ftype=atype; + fproblem_source=aproblem_source ? new String(*aproblem_source) : 0; + + if(!comment_fmt) { fcomment=0; + } else if (!strcmp(comment_fmt, "%s")) { // to avoid MAX_STRING limit + va_list args; + va_start(args, comment_fmt); + fcomment=va_arg(args, const char *); + fcomment=fcomment ? pa_strdup(fcomment) : 0; + va_end(args); + } else { + 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 { + return fproblem_source && !fproblem_source->is_empty() ? fproblem_source : 0; } -#endif