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