Annotation of parser3/src/main/pa_exception.C, revision 1.39

1.13      parser      1: /** @file
                      2:        Parser: exception class.
                      3: 
1.37      paf         4:        Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.38      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.13      parser      6: 
1.39    ! paf         7:        $Id: pa_exception.C,v 1.38 2002/02/08 08:30:16 paf Exp $
1.13      parser      8: */
                      9: 
                     10: #include "pa_common.h"
                     11: #include "pa_exception.h"
1.31      paf        12: #include "pa_globals.h"
1.39    ! paf        13: #include "pa_sapi.h"
1.13      parser     14: 
1.23      paf        15: Exception::Exception() {
                     16:        ftype=fcode=fproblem_source=0;
1.26      paf        17:        owns_comment=false; fcomment=0;
1.23      paf        18: }
1.34      paf        19: Exception::Exception(const String *atype, const String *acode,
                     20:                                          const String *aproblem_source, 
                     21:                                          const char *comment_fmt, ...) {
1.15      parser     22:        //_asm int 3;
1.27      paf        23: //__asm__("int3");
1.30      paf        24:        ftype=atype;
                     25:        fcode=acode;
                     26:        fproblem_source=aproblem_source;
                     27:        owns_comment=true;
1.27      paf        28: 
1.13      parser     29:        if(comment_fmt) {
1.26      paf        30:                fcomment=(char *)malloc(MAX_STRING);
1.39    ! paf        31:                if(!fcomment)
        !            32:                        SAPI::die("out of memory in 'Exception::Exception', failed to allocated %u bytes", MAX_STRING);
1.34      paf        33:                va_list args;
                     34:                va_start(args, comment_fmt);
1.13      parser     35:                vsnprintf(fcomment, MAX_STRING, comment_fmt, args);
1.34      paf        36:                va_end(args);
1.26      paf        37:        } else
                     38:                fcomment=0;
                     39: }
1.33      paf        40: Exception::Exception(const Exception& src) : 
                     41:        ftype(src.ftype),
                     42:        fcode(src.fcode),
                     43:        fproblem_source(src.fproblem_source),
                     44:        fcomment(src.fcomment),
                     45:        owns_comment(src.owns_comment) {
                     46:        // that ugly string got from STL, along with principal ideal
                     47:        const_cast<Exception *>(&src)->owns_comment=false;
                     48: }
                     49: Exception& Exception::operator =(const Exception& src) {
                     50:        ftype=src.ftype;
                     51:        fcode=src.fcode;
                     52:        fproblem_source=src.fproblem_source;
                     53: 
                     54:        if(owns_comment)
                     55:                free(fcomment);
                     56:        fcomment=src.fcomment;
                     57:        // that ugly string got from STL, along with principal ideal
                     58:        owns_comment=src.owns_comment;  ((Exception*)&src)->owns_comment=false;
                     59:        
                     60:        return *this;
                     61: }
                     62: Exception::~Exception() {
                     63:        if(owns_comment)
                     64:                free(fcomment);
                     65: }
                     66: 
                     67: #ifdef XML
1.28      paf        68: Exception::Exception(
                     69:        const String *atype, const String *acode,
                     70:        const String *aproblem_source, 
                     71:        GdomeException& exc) :
                     72:        ftype(atype),
                     73:        fcode(acode),
                     74:        fproblem_source(aproblem_source),
                     75:        owns_comment(true) {
                     76: 
1.31      paf        77:        const char *xml_generic_errors=xmlGenericErrors();
                     78:        if(xml_generic_errors || exc) {
1.28      paf        79:                const char *s;
                     80:                switch((GdomeExceptionCode)exc) {
                     81:                case GDOME_NOEXCEPTION_ERR: s="NOEXCEPTION_ERR"; break;
                     82:                case GDOME_INDEX_SIZE_ERR: s="INDEX_SIZE_ERR"; break;
                     83:                case GDOME_DOMSTRING_SIZE_ERR: s="DOMSTRING_SIZE_ERR"; break;
                     84:                case GDOME_HIERARCHY_REQUEST_ERR: s="HIERARCHY_REQUEST_ERR"; break;
                     85:                case GDOME_WRONG_DOCUMENT_ERR: s="WRONG_DOCUMENT_ERR"; break;
                     86:                case GDOME_INVALID_CHARACTER_ERR: s="INVALID_CHARACTER_ERR"; break;
                     87:                case GDOME_NO_DATA_ALLOWED_ERR: s="NO_DATA_ALLOWED_ERR"; break;
                     88:                case GDOME_NO_MODIFICATION_ALLOWED_ERR: s="NO_MODIFICATION_ALLOWED_ERR"; break;
                     89:                case GDOME_NOT_FOUND_ERR: s="NOT_FOUND_ERR"; break;
                     90:                case GDOME_NOT_SUPPORTED_ERR: s="NOT_SUPPORTED_ERR"; break;
                     91:                case GDOME_INUSE_ATTRIBUTE_ERR: s="INUSE_ATTRIBUTE_ERR"; break;
                     92:                case GDOME_INVALID_STATE_ERR: s="INVALID_STATE_ERR"; break;
                     93:                case GDOME_SYNTAX_ERR: s="SYNTAX_ERR"; break;
                     94:                case GDOME_INVALID_MODIFICATION_ERR: s="INVALID_MODIFICATION_ERR"; break;
                     95:                case GDOME_NAMESPACE_ERR: s="NAMESPACE_ERR"; break;
                     96:                case GDOME_INVALID_ACCESS_ERR: s="INVALID_ACCESS_ERR"; break;
                     97:                case GDOME_NULL_POINTER_ERR: s="NULL_POINTER_ERR"; break;
                     98:                default: s="<UNKNOWN CODE>"; break;
                     99:                }
                    100:                
                    101:                fcomment=(char *)malloc(MAX_STRING);
1.36      paf       102:                const char *xml_error_message;
                    103:                const char *xml_error_prefix;
                    104:                if(xml_generic_errors) {
                    105:                        xml_error_prefix="\n";
                    106:                        xml_error_message=xml_generic_errors;
                    107:                } else {
                    108:                        xml_error_prefix="";
                    109:                        xml_error_message="";
                    110:                }
1.32      paf       111:                if(exc)
                    112:                        snprintf(fcomment, MAX_STRING, 
1.35      paf       113:                                "DOMException %s (%d)."
                    114:                                "%s%s", 
1.32      paf       115:                                        s,  // decoded code of exception
                    116:                                        exc, // DOM exception code
1.35      paf       117:                                        xml_error_prefix, xml_error_message // xml generic messages accumulated
1.32      paf       118:                        );
                    119:                else // no DOM exception
                    120:                        snprintf(fcomment, MAX_STRING, 
                    121:                                "%s", 
                    122:                                        xml_error_message // xml generic messages accumulated
                    123:                        );
1.31      paf       124:                if(xml_generic_errors)
                    125:                        free((void *)xml_generic_errors);
1.28      paf       126:        } else
1.29      paf       127:                fcomment=0;
1.28      paf       128: }
1.18      parser    129: #endif

E-mail: