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

1.13      parser      1: /** @file
                      2:        Parser: exception class.
                      3: 
                      4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.24      paf         5:        Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.13      parser      6: 
1.31    ! paf         7:        $Id: pa_exception.C,v 1.30 2001/12/29 08:39:05 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.13      parser     13: 
1.23      paf        14: Exception::Exception() {
                     15:        ftype=fcode=fproblem_source=0;
1.26      paf        16:        owns_comment=false; fcomment=0;
1.23      paf        17: }
1.30      paf        18: void Exception::initialize(
                     19:        const String *atype, const String *acode,
                     20:        const String *aproblem_source, 
                     21:        const char *comment_fmt, va_list args) {
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.13      parser     31:                vsnprintf(fcomment, MAX_STRING, comment_fmt, args);
1.26      paf        32:        } else
                     33:                fcomment=0;
1.30      paf        34: }
                     35: Exception::Exception(
                     36:        const String *atype, const String *acode,
                     37:        const String *aproblem_source, 
                     38:        const char *comment_fmt, va_list args) {
                     39:        initialize(atype, acode, aproblem_source, comment_fmt, args);
                     40: }
                     41: Exception::Exception(const String *atype, const String *acode,
                     42:                                          const String *aproblem_source, 
                     43:                                          const char *comment_fmt, ...) {
                     44:        va_list args;
                     45:     va_start(args, comment_fmt);
                     46:        initialize(atype, acode, aproblem_source, comment_fmt, args);
                     47:        va_end(args);
1.26      paf        48: }
1.28      paf        49: Exception::Exception(
                     50:        const String *atype, const String *acode,
                     51:        const String *aproblem_source, 
                     52:        GdomeException& exc) :
                     53:        ftype(atype),
                     54:        fcode(acode),
                     55:        fproblem_source(aproblem_source),
                     56:        owns_comment(true) {
                     57: 
1.31    ! paf        58:        const char *xml_generic_errors=xmlGenericErrors();
        !            59:        if(xml_generic_errors || exc) {
1.28      paf        60:                const char *s;
                     61:                switch((GdomeExceptionCode)exc) {
                     62:                case GDOME_NOEXCEPTION_ERR: s="NOEXCEPTION_ERR"; break;
                     63:                case GDOME_INDEX_SIZE_ERR: s="INDEX_SIZE_ERR"; break;
                     64:                case GDOME_DOMSTRING_SIZE_ERR: s="DOMSTRING_SIZE_ERR"; break;
                     65:                case GDOME_HIERARCHY_REQUEST_ERR: s="HIERARCHY_REQUEST_ERR"; break;
                     66:                case GDOME_WRONG_DOCUMENT_ERR: s="WRONG_DOCUMENT_ERR"; break;
                     67:                case GDOME_INVALID_CHARACTER_ERR: s="INVALID_CHARACTER_ERR"; break;
                     68:                case GDOME_NO_DATA_ALLOWED_ERR: s="NO_DATA_ALLOWED_ERR"; break;
                     69:                case GDOME_NO_MODIFICATION_ALLOWED_ERR: s="NO_MODIFICATION_ALLOWED_ERR"; break;
                     70:                case GDOME_NOT_FOUND_ERR: s="NOT_FOUND_ERR"; break;
                     71:                case GDOME_NOT_SUPPORTED_ERR: s="NOT_SUPPORTED_ERR"; break;
                     72:                case GDOME_INUSE_ATTRIBUTE_ERR: s="INUSE_ATTRIBUTE_ERR"; break;
                     73:                case GDOME_INVALID_STATE_ERR: s="INVALID_STATE_ERR"; break;
                     74:                case GDOME_SYNTAX_ERR: s="SYNTAX_ERR"; break;
                     75:                case GDOME_INVALID_MODIFICATION_ERR: s="INVALID_MODIFICATION_ERR"; break;
                     76:                case GDOME_NAMESPACE_ERR: s="NAMESPACE_ERR"; break;
                     77:                case GDOME_INVALID_ACCESS_ERR: s="INVALID_ACCESS_ERR"; break;
                     78:                case GDOME_NULL_POINTER_ERR: s="NULL_POINTER_ERR"; break;
                     79:                default: s="<UNKNOWN CODE>"; break;
                     80:                }
                     81:                
                     82:                fcomment=(char *)malloc(MAX_STRING);
                     83:                snprintf(fcomment, MAX_STRING, 
1.31    ! paf        84:                        "DOMException %s (%d).\n"
        !            85:                        "%s", 
1.28      paf        86:                                s,  // decoded code of exception
1.31    ! paf        87:                                exc, // DOM exception code
        !            88:                                xml_generic_errors?xml_generic_errors:"<no xml_generic_errors>" // xml generic messages accumulated
1.28      paf        89:                );
1.31    ! paf        90:                if(xml_generic_errors)
        !            91:                        free((void *)xml_generic_errors);
1.28      paf        92:        } else
1.29      paf        93:                fcomment=0;
1.28      paf        94: }
                     95: 
                     96: 
1.26      paf        97: Exception::Exception(const Exception& src) : 
                     98:        ftype(src.ftype),
                     99:        fcode(src.fcode),
                    100:        fproblem_source(src.fproblem_source),
                    101:        fcomment(src.fcomment),
                    102:        owns_comment(src.owns_comment) {
                    103:        // that ugly string got from STL, along with principal ideal
                    104:        const_cast<Exception *>(&src)->owns_comment=false;
                    105: }
                    106: Exception& Exception::operator =(const Exception& src) {
                    107:        ftype=src.ftype;
                    108:        fcode=src.fcode;
                    109:        fproblem_source=src.fproblem_source;
                    110: 
                    111:        if(owns_comment)
                    112:                free(fcomment);
                    113:        fcomment=src.fcomment;
                    114:        // that ugly string got from STL, along with principal ideal
                    115:        owns_comment=src.owns_comment;  ((Exception*)&src)->owns_comment=false;
                    116:        
                    117:        return *this;
                    118: }
                    119: Exception::~Exception() {
                    120:        if(owns_comment)
                    121:                free(fcomment);
1.13      parser    122: }
1.17      parser    123: 
1.18      parser    124: #ifdef XML
1.28      paf       125: /*
1.22      parser    126: void Exception::provide_source(Pool& pool, const String *source, const XSLException& e) {
1.17      parser    127:        if(e.getURI().empty())
1.20      parser    128:                throw Exception(0, 0,
1.17      parser    129:                        source,
                    130:                        "%s (%s)",
                    131:                                pool.transcode_cstr(e.getMessage()),  // message for exception
                    132:                                pool.transcode_cstr(e.getType()) // type of exception
                    133:                );
                    134:        else
1.20      parser    135:                throw Exception(0, 0,
1.17      parser    136:                        source,
                    137:                        "%s (%s). %s(%d:%d)'", 
                    138:                                pool.transcode_cstr(e.getMessage()),  // message for exception
                    139:                                pool.transcode_cstr(e.getType()), // type of exception
                    140:                                
                    141:                                pool.transcode_cstr(e.getURI()),  // URI for the associated document, if any
                    142:                                e.getLineNumber(),  // line number, or -1 if unknown
                    143:                                e.getColumnNumber() // column number, or -1 if unknown
                    144:                );
                    145: }
                    146: 
1.22      parser    147: void Exception::provide_source(Pool& pool, const String *source, const SAXException& e) {
1.20      parser    148:        throw Exception(0, 0,
1.17      parser    149:                source,
                    150:                "%s",
                    151:                        pool.transcode_cstr(XalanDOMString(e.getMessage()))  // message for exception
                    152:        );
                    153: }
1.22      parser    154: void Exception::provide_source(Pool& pool, const String *source, const SAXParseException& e) {
1.20      parser    155:        throw Exception(0, 0,
1.17      parser    156:                source,
                    157:                "%s. %s(%d:%d)",
                    158:                        pool.transcode_cstr(XalanDOMString(e.getMessage())),  // message for exception
                    159:                        e.getSystemId()?pool.transcode_cstr(XalanDOMString(e.getSystemId())):"block", // file of exception
                    160:                        e.getLineNumber(), e.getColumnNumber() // line:col
                    161:        );
                    162: }
                    163: 
                    164: 
1.22      parser    165: void Exception::provide_source(Pool& pool, const String *source, const XMLException& e) {
1.20      parser    166:        throw Exception(0, 0,
1.17      parser    167:                source,
                    168:                "%s (%s). %s(%d)'", 
                    169:                        pool.transcode_cstr(XalanDOMString(e.getMessage())),  // message for exception
1.20      parser    170:                        pool.transcode_cstr(XalanDOMString(e.getType())), // type of exception
1.17      parser    171:                        
                    172:                        e.getSrcFile()?e.getSrcFile():"block", // file of exception
                    173:                        e.getSrcLine()  // line number
                    174:                        //e.getCode()
                    175:        );
                    176: }
                    177: 
1.28      paf       178: */
1.18      parser    179: #endif

E-mail: