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