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

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

E-mail: