Annotation of parser3/src/main/pa_exception.C, revision 1.35
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.35 ! paf 7: $Id: pa_exception.C,v 1.34 2002/01/23 10:38:18 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.34 paf 18: Exception::Exception(const String *atype, const String *acode,
19: const String *aproblem_source,
20: const char *comment_fmt, ...) {
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.34 paf 30: va_list args;
31: va_start(args, comment_fmt);
1.13 parser 32: vsnprintf(fcomment, MAX_STRING, comment_fmt, args);
1.34 paf 33: va_end(args);
1.26 paf 34: } else
35: fcomment=0;
36: }
1.33 paf 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);
62: }
63:
64: #ifdef XML
1.28 paf 65: Exception::Exception(
66: const String *atype, const String *acode,
67: const String *aproblem_source,
68: GdomeException& exc) :
69: ftype(atype),
70: fcode(acode),
71: fproblem_source(aproblem_source),
72: owns_comment(true) {
73:
1.31 paf 74: const char *xml_generic_errors=xmlGenericErrors();
75: if(xml_generic_errors || exc) {
1.28 paf 76: const char *s;
77: switch((GdomeExceptionCode)exc) {
78: case GDOME_NOEXCEPTION_ERR: s="NOEXCEPTION_ERR"; break;
79: case GDOME_INDEX_SIZE_ERR: s="INDEX_SIZE_ERR"; break;
80: case GDOME_DOMSTRING_SIZE_ERR: s="DOMSTRING_SIZE_ERR"; break;
81: case GDOME_HIERARCHY_REQUEST_ERR: s="HIERARCHY_REQUEST_ERR"; break;
82: case GDOME_WRONG_DOCUMENT_ERR: s="WRONG_DOCUMENT_ERR"; break;
83: case GDOME_INVALID_CHARACTER_ERR: s="INVALID_CHARACTER_ERR"; break;
84: case GDOME_NO_DATA_ALLOWED_ERR: s="NO_DATA_ALLOWED_ERR"; break;
85: case GDOME_NO_MODIFICATION_ALLOWED_ERR: s="NO_MODIFICATION_ALLOWED_ERR"; break;
86: case GDOME_NOT_FOUND_ERR: s="NOT_FOUND_ERR"; break;
87: case GDOME_NOT_SUPPORTED_ERR: s="NOT_SUPPORTED_ERR"; break;
88: case GDOME_INUSE_ATTRIBUTE_ERR: s="INUSE_ATTRIBUTE_ERR"; break;
89: case GDOME_INVALID_STATE_ERR: s="INVALID_STATE_ERR"; break;
90: case GDOME_SYNTAX_ERR: s="SYNTAX_ERR"; break;
91: case GDOME_INVALID_MODIFICATION_ERR: s="INVALID_MODIFICATION_ERR"; break;
92: case GDOME_NAMESPACE_ERR: s="NAMESPACE_ERR"; break;
93: case GDOME_INVALID_ACCESS_ERR: s="INVALID_ACCESS_ERR"; break;
94: case GDOME_NULL_POINTER_ERR: s="NULL_POINTER_ERR"; break;
95: default: s="<UNKNOWN CODE>"; break;
96: }
97:
98: fcomment=(char *)malloc(MAX_STRING);
1.32 paf 99: const char *xml_error_message=
100: xml_generic_errors?xml_generic_errors:"<no xml_generic_errors>";
1.35 ! paf 101: const char *xml_error_prefix=
! 102: xml_generic_errors?"\n":"";
1.32 paf 103: if(exc)
104: snprintf(fcomment, MAX_STRING,
1.35 ! paf 105: "DOMException %s (%d)."
! 106: "%s%s",
1.32 paf 107: s, // decoded code of exception
108: exc, // DOM exception code
1.35 ! paf 109: xml_error_prefix, xml_error_message // xml generic messages accumulated
1.32 paf 110: );
111: else // no DOM exception
112: snprintf(fcomment, MAX_STRING,
113: "%s",
114: xml_error_message // xml generic messages accumulated
115: );
1.31 paf 116: if(xml_generic_errors)
117: free((void *)xml_generic_errors);
1.28 paf 118: } else
1.29 paf 119: fcomment=0;
1.28 paf 120: }
1.18 parser 121: #endif
E-mail: