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

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.32    ! paf         7:        $Id: pa_exception.C,v 1.31 2002/01/21 12:10:08 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);
1.32    ! paf        83:                const char *xml_error_message=
        !            84:                        xml_generic_errors?xml_generic_errors:"<no xml_generic_errors>";
        !            85:                if(exc)
        !            86:                        snprintf(fcomment, MAX_STRING, 
        !            87:                                "DOMException %s (%d).\n"
        !            88:                                "%s", 
        !            89:                                        s,  // decoded code of exception
        !            90:                                        exc, // DOM exception code
        !            91:                                        xml_error_message // xml generic messages accumulated
        !            92:                        );
        !            93:                else // no DOM exception
        !            94:                        snprintf(fcomment, MAX_STRING, 
        !            95:                                "%s", 
        !            96:                                        xml_error_message // xml generic messages accumulated
        !            97:                        );
1.31      paf        98:                if(xml_generic_errors)
                     99:                        free((void *)xml_generic_errors);
1.28      paf       100:        } else
1.29      paf       101:                fcomment=0;
1.28      paf       102: }
                    103: 
                    104: 
1.26      paf       105: Exception::Exception(const Exception& src) : 
                    106:        ftype(src.ftype),
                    107:        fcode(src.fcode),
                    108:        fproblem_source(src.fproblem_source),
                    109:        fcomment(src.fcomment),
                    110:        owns_comment(src.owns_comment) {
                    111:        // that ugly string got from STL, along with principal ideal
                    112:        const_cast<Exception *>(&src)->owns_comment=false;
                    113: }
                    114: Exception& Exception::operator =(const Exception& src) {
                    115:        ftype=src.ftype;
                    116:        fcode=src.fcode;
                    117:        fproblem_source=src.fproblem_source;
                    118: 
                    119:        if(owns_comment)
                    120:                free(fcomment);
                    121:        fcomment=src.fcomment;
                    122:        // that ugly string got from STL, along with principal ideal
                    123:        owns_comment=src.owns_comment;  ((Exception*)&src)->owns_comment=false;
                    124:        
                    125:        return *this;
                    126: }
                    127: Exception::~Exception() {
                    128:        if(owns_comment)
                    129:                free(fcomment);
1.13      parser    130: }
1.17      parser    131: 
1.18      parser    132: #ifdef XML
1.28      paf       133: /*
1.22      parser    134: void Exception::provide_source(Pool& pool, const String *source, const XSLException& e) {
1.17      parser    135:        if(e.getURI().empty())
1.20      parser    136:                throw Exception(0, 0,
1.17      parser    137:                        source,
                    138:                        "%s (%s)",
                    139:                                pool.transcode_cstr(e.getMessage()),  // message for exception
                    140:                                pool.transcode_cstr(e.getType()) // type of exception
                    141:                );
                    142:        else
1.20      parser    143:                throw Exception(0, 0,
1.17      parser    144:                        source,
                    145:                        "%s (%s). %s(%d:%d)'", 
                    146:                                pool.transcode_cstr(e.getMessage()),  // message for exception
                    147:                                pool.transcode_cstr(e.getType()), // type of exception
                    148:                                
                    149:                                pool.transcode_cstr(e.getURI()),  // URI for the associated document, if any
                    150:                                e.getLineNumber(),  // line number, or -1 if unknown
                    151:                                e.getColumnNumber() // column number, or -1 if unknown
                    152:                );
                    153: }
                    154: 
1.22      parser    155: void Exception::provide_source(Pool& pool, const String *source, const SAXException& e) {
1.20      parser    156:        throw Exception(0, 0,
1.17      parser    157:                source,
                    158:                "%s",
                    159:                        pool.transcode_cstr(XalanDOMString(e.getMessage()))  // message for exception
                    160:        );
                    161: }
1.22      parser    162: void Exception::provide_source(Pool& pool, const String *source, const SAXParseException& e) {
1.20      parser    163:        throw Exception(0, 0,
1.17      parser    164:                source,
                    165:                "%s. %s(%d:%d)",
                    166:                        pool.transcode_cstr(XalanDOMString(e.getMessage())),  // message for exception
                    167:                        e.getSystemId()?pool.transcode_cstr(XalanDOMString(e.getSystemId())):"block", // file of exception
                    168:                        e.getLineNumber(), e.getColumnNumber() // line:col
                    169:        );
                    170: }
                    171: 
                    172: 
1.22      parser    173: void Exception::provide_source(Pool& pool, const String *source, const XMLException& e) {
1.20      parser    174:        throw Exception(0, 0,
1.17      parser    175:                source,
                    176:                "%s (%s). %s(%d)'", 
                    177:                        pool.transcode_cstr(XalanDOMString(e.getMessage())),  // message for exception
1.20      parser    178:                        pool.transcode_cstr(XalanDOMString(e.getType())), // type of exception
1.17      parser    179:                        
                    180:                        e.getSrcFile()?e.getSrcFile():"block", // file of exception
                    181:                        e.getSrcLine()  // line number
                    182:                        //e.getCode()
                    183:        );
                    184: }
                    185: 
1.28      paf       186: */
1.18      parser    187: #endif

E-mail: