Annotation of parser3/src/main/pa_exception.C, revision 1.33
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.33 ! paf 7: $Id: pa_exception.C,v 1.32 2002/01/21 12:33:26 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.33 ! paf 49: Exception::Exception(const Exception& src) :
! 50: ftype(src.ftype),
! 51: fcode(src.fcode),
! 52: fproblem_source(src.fproblem_source),
! 53: fcomment(src.fcomment),
! 54: owns_comment(src.owns_comment) {
! 55: // that ugly string got from STL, along with principal ideal
! 56: const_cast<Exception *>(&src)->owns_comment=false;
! 57: }
! 58: Exception& Exception::operator =(const Exception& src) {
! 59: ftype=src.ftype;
! 60: fcode=src.fcode;
! 61: fproblem_source=src.fproblem_source;
! 62:
! 63: if(owns_comment)
! 64: free(fcomment);
! 65: fcomment=src.fcomment;
! 66: // that ugly string got from STL, along with principal ideal
! 67: owns_comment=src.owns_comment; ((Exception*)&src)->owns_comment=false;
! 68:
! 69: return *this;
! 70: }
! 71: Exception::~Exception() {
! 72: if(owns_comment)
! 73: free(fcomment);
! 74: }
! 75:
! 76: #ifdef XML
1.28 paf 77: Exception::Exception(
78: const String *atype, const String *acode,
79: const String *aproblem_source,
80: GdomeException& exc) :
81: ftype(atype),
82: fcode(acode),
83: fproblem_source(aproblem_source),
84: owns_comment(true) {
85:
1.31 paf 86: const char *xml_generic_errors=xmlGenericErrors();
87: if(xml_generic_errors || exc) {
1.28 paf 88: const char *s;
89: switch((GdomeExceptionCode)exc) {
90: case GDOME_NOEXCEPTION_ERR: s="NOEXCEPTION_ERR"; break;
91: case GDOME_INDEX_SIZE_ERR: s="INDEX_SIZE_ERR"; break;
92: case GDOME_DOMSTRING_SIZE_ERR: s="DOMSTRING_SIZE_ERR"; break;
93: case GDOME_HIERARCHY_REQUEST_ERR: s="HIERARCHY_REQUEST_ERR"; break;
94: case GDOME_WRONG_DOCUMENT_ERR: s="WRONG_DOCUMENT_ERR"; break;
95: case GDOME_INVALID_CHARACTER_ERR: s="INVALID_CHARACTER_ERR"; break;
96: case GDOME_NO_DATA_ALLOWED_ERR: s="NO_DATA_ALLOWED_ERR"; break;
97: case GDOME_NO_MODIFICATION_ALLOWED_ERR: s="NO_MODIFICATION_ALLOWED_ERR"; break;
98: case GDOME_NOT_FOUND_ERR: s="NOT_FOUND_ERR"; break;
99: case GDOME_NOT_SUPPORTED_ERR: s="NOT_SUPPORTED_ERR"; break;
100: case GDOME_INUSE_ATTRIBUTE_ERR: s="INUSE_ATTRIBUTE_ERR"; break;
101: case GDOME_INVALID_STATE_ERR: s="INVALID_STATE_ERR"; break;
102: case GDOME_SYNTAX_ERR: s="SYNTAX_ERR"; break;
103: case GDOME_INVALID_MODIFICATION_ERR: s="INVALID_MODIFICATION_ERR"; break;
104: case GDOME_NAMESPACE_ERR: s="NAMESPACE_ERR"; break;
105: case GDOME_INVALID_ACCESS_ERR: s="INVALID_ACCESS_ERR"; break;
106: case GDOME_NULL_POINTER_ERR: s="NULL_POINTER_ERR"; break;
107: default: s="<UNKNOWN CODE>"; break;
108: }
109:
110: fcomment=(char *)malloc(MAX_STRING);
1.32 paf 111: const char *xml_error_message=
112: xml_generic_errors?xml_generic_errors:"<no xml_generic_errors>";
113: if(exc)
114: snprintf(fcomment, MAX_STRING,
115: "DOMException %s (%d).\n"
116: "%s",
117: s, // decoded code of exception
118: exc, // DOM exception code
119: xml_error_message // xml generic messages accumulated
120: );
121: else // no DOM exception
122: snprintf(fcomment, MAX_STRING,
123: "%s",
124: xml_error_message // xml generic messages accumulated
125: );
1.31 paf 126: if(xml_generic_errors)
127: free((void *)xml_generic_errors);
1.28 paf 128: } else
1.29 paf 129: fcomment=0;
1.28 paf 130: }
1.18 parser 131: #endif
E-mail: