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

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.26    ! paf         7:        $Id: pa_exception.C,v 1.25 2001/11/15 18:21:31 paf Exp $
1.13      parser      8: */
                      9: 
                     10: #include "pa_common.h"
                     11: #include "pa_exception.h"
                     12: 
1.23      paf        13: Exception::Exception() {
                     14:        ftype=fcode=fproblem_source=0;
1.26    ! paf        15:        owns_comment=false; fcomment=0;
1.23      paf        16: }
1.19      parser     17: Exception::Exception(const String *atype, const String *acode,
1.13      parser     18:                                          const String *aproblem_source, 
1.19      parser     19:                                          const char *comment_fmt, ...) {
1.15      parser     20:        //_asm int 3;
1.13      parser     21:        ftype=atype;
                     22:        fcode=acode;
                     23:        fproblem_source=aproblem_source;
1.26    ! paf        24:        owns_comment=true;
1.13      parser     25: 
                     26:        if(comment_fmt) {
                     27:                va_list args;
                     28:                va_start(args, comment_fmt);
1.26    ! paf        29:                fcomment=(char *)malloc(MAX_STRING);
1.13      parser     30:                vsnprintf(fcomment, MAX_STRING, comment_fmt, args);
                     31:                va_end(args);
1.26    ! paf        32:        } else
        !            33:                fcomment=0;
        !            34: }
        !            35: Exception::Exception(const Exception& src) : 
        !            36:        ftype(src.ftype),
        !            37:        fcode(src.fcode),
        !            38:        fproblem_source(src.fproblem_source),
        !            39:        fcomment(src.fcomment),
        !            40:        owns_comment(src.owns_comment) {
        !            41:        // that ugly string got from STL, along with principal ideal
        !            42:        const_cast<Exception *>(&src)->owns_comment=false;
        !            43: }
        !            44: Exception& Exception::operator =(const Exception& src) {
        !            45:        ftype=src.ftype;
        !            46:        fcode=src.fcode;
        !            47:        fproblem_source=src.fproblem_source;
        !            48: 
        !            49:        if(owns_comment)
        !            50:                free(fcomment);
        !            51:        fcomment=src.fcomment;
        !            52:        // that ugly string got from STL, along with principal ideal
        !            53:        owns_comment=src.owns_comment;  ((Exception*)&src)->owns_comment=false;
        !            54:        
        !            55:        return *this;
        !            56: }
        !            57: Exception::~Exception() {
        !            58:        if(owns_comment)
        !            59:                free(fcomment);
1.13      parser     60: }
1.17      parser     61: 
1.18      parser     62: #ifdef XML
1.22      parser     63: void Exception::provide_source(Pool& pool, const String *source, const XSLException& e) {
1.17      parser     64:        if(e.getURI().empty())
1.20      parser     65:                throw Exception(0, 0,
1.17      parser     66:                        source,
                     67:                        "%s (%s)",
                     68:                                pool.transcode_cstr(e.getMessage()),  // message for exception
                     69:                                pool.transcode_cstr(e.getType()) // type of exception
                     70:                );
                     71:        else
1.20      parser     72:                throw Exception(0, 0,
1.17      parser     73:                        source,
                     74:                        "%s (%s). %s(%d:%d)'", 
                     75:                                pool.transcode_cstr(e.getMessage()),  // message for exception
                     76:                                pool.transcode_cstr(e.getType()), // type of exception
                     77:                                
                     78:                                pool.transcode_cstr(e.getURI()),  // URI for the associated document, if any
                     79:                                e.getLineNumber(),  // line number, or -1 if unknown
                     80:                                e.getColumnNumber() // column number, or -1 if unknown
                     81:                );
                     82: }
                     83: 
1.22      parser     84: void Exception::provide_source(Pool& pool, const String *source, const SAXException& e) {
1.20      parser     85:        throw Exception(0, 0,
1.17      parser     86:                source,
                     87:                "%s",
                     88:                        pool.transcode_cstr(XalanDOMString(e.getMessage()))  // message for exception
                     89:        );
                     90: }
1.22      parser     91: void Exception::provide_source(Pool& pool, const String *source, const SAXParseException& e) {
1.20      parser     92:        throw Exception(0, 0,
1.17      parser     93:                source,
                     94:                "%s. %s(%d:%d)",
                     95:                        pool.transcode_cstr(XalanDOMString(e.getMessage())),  // message for exception
                     96:                        e.getSystemId()?pool.transcode_cstr(XalanDOMString(e.getSystemId())):"block", // file of exception
                     97:                        e.getLineNumber(), e.getColumnNumber() // line:col
                     98:        );
                     99: }
                    100: 
                    101: 
1.22      parser    102: void Exception::provide_source(Pool& pool, const String *source, const XMLException& e) {
1.20      parser    103:        throw Exception(0, 0,
1.17      parser    104:                source,
                    105:                "%s (%s). %s(%d)'", 
                    106:                        pool.transcode_cstr(XalanDOMString(e.getMessage())),  // message for exception
1.20      parser    107:                        pool.transcode_cstr(XalanDOMString(e.getType())), // type of exception
1.17      parser    108:                        
                    109:                        e.getSrcFile()?e.getSrcFile():"block", // file of exception
                    110:                        e.getSrcLine()  // line number
                    111:                        //e.getCode()
                    112:        );
                    113: }
                    114: 
1.22      parser    115: void Exception::provide_source(Pool& pool, const String *source, const XalanDOMException& e) {
1.17      parser    116:        const char *s;
                    117:        int code=(int)e.getExceptionCode();
                    118:        switch(code) {
                    119:        case 1: s="INDEX_SIZE_ERR"; break;
                    120:        case 2: s="DOMSTRING_SIZE_ERR"; break;
                    121:        case 3: s="HIERARCHY_REQUEST_ERR"; break;
                    122:        case 4: s="WRONG_DOCUMENT_ERR"; break;
                    123:        case 5: s="INVALID_CHARACTER_ERR"; break;
                    124:        case 6: s="NO_DATA_ALLOWED_ERR"; break;
                    125:        case 7: s="NO_MODIFICATION_ALLOWED_ERR"; break;
                    126:        case 8: s="NOT_FOUND_ERR"; break;
                    127:        case 9: s="NOT_SUPPORTED_ERR"; break;
                    128:        case 10: s="INUSE_ATTRIBUTE_ERR"; break;
                    129:        case 11: s="INVALID_STATE_ERR"; break;
                    130:        case 12: s="SYNTAX_ERR"; break;
                    131:        case 13: s="INVALID_MODIFICATION_ERR"; break;
                    132:        case 14: s="NAMESPACE_ERR"; break;
                    133:        case 15: s="INVALID_ACCESS_ERR"; break;
                    134:        case 201: s="UNKNOWN_ERR"; break;
                    135:        case 202: s="TRANSCODING_ERR"; break;
                    136:        default: s="<UNKNOWN CODE>"; break;
                    137:        }
1.20      parser    138:        throw Exception(0, 0,
1.17      parser    139:                source,
                    140:                "XalanDOMException %s (%d)",
                    141:                        s,  // decoded code of exception
                    142:                        code // code of exception
                    143:        );
                    144: }
1.18      parser    145: #endif

E-mail: