theKernel 10.0
Loading...
Searching...
No Matches
MkExceptionC_atl.c
Go to the documentation of this file.
1
9/* LABEL-NO */
10
11#define META_FILE_NAME "MkExceptionC_atl.c"
12
14#include "mk_check_atl.h"
15
16/* LABEL-END */
17
18//
19// *********************************************************************************
20//
21
25
28void MK(MkExceptionC_Raise) (
30 MK_MNGN const expobj,
31 MK_STRN const doc,
32 MK_STRN const callfunc,
33 MK_I32 callline
34)
35{
36 static MkThreadLocal bool in_duty = false;
37 static MkThreadLocal MK_ERR newerr = NULL;
38 // Stop the 'raise' recursion
39 if (in_duty) {
40 Tcl_SetResult(interp, "WARNING: detect recursion on 'MkExceptionC_Raise'", TCL_VOLATILE);
41 MkLogV_2(MK_ERROR_PRINT, "%s\n", Tcl_GetStringResult(interp));
42 in_duty = false;
43 return;
44 }
45 MK_ERR err = MkErrorFORMAT_1M(expobj);
46 MkErrorStackFormat(err,doc,callfunc,callline);
47 int lvl = 0;
48 while (MK(Get_Call_Stack)(OT_MK_CALL err, lvl)) lvl--;
49
50 if (newerr) MkRefDecr_X(newerr);
51
52 newerr = MkErrCheck(expobj) && expobj != err ? (MK_ERR)expobj : MkErrorDup(err);
53 MkRefIncr_1X(newerr);
54
55 in_duty = true;
56 OT_OBJ_T tclErrObj = NS(MkErrorC_ObjNew) (OT_MK_CALL newerr);
57 in_duty = false;
58
59 if (tclErrObj == NULL) {
60 Tcl_SetResult(interp, "WARNING: failed to create an error-object", TCL_STATIC);
61 Tcl_SetErrorCode(interp, "ATL", "ERROR", "CREATE", NULL);
62 MkLogV_2(MK_ERROR_PRINT, "%s\n", Tcl_GetStringResult(interp));
63 return;
64 }
65
66//printV("err=%p, object=%s\n", err, OT_LNG_NAME_FROM_OBJ(tclErrObj))
67
68 OT_OBJ_T lst = Tcl_NewObj();
69 check_LNG(Tcl_ListObjAppendElement(interp,lst,amkrt->MkExceptionC)) goto error;
70 check_LNG(Tcl_ListObjAppendElement(interp,lst,tclErrObj)) goto error;
71 Tcl_SetObjErrorCode(interp,lst);
72 Tcl_SetVar2Ex(interp,"errorCode",NULL,lst,TCL_GLOBAL_ONLY);
73 Tcl_SetResult(interp, (MK_STR) MkErrorGetText_0E(), TCL_VOLATILE);
74
75 MkErrorReset_1(err);
76error:
77 return;
78}
79
81MK_ERR MK(MkExceptionC_Catch) (
83 MK_MNG const expobj,
84 MK_EXP const exception,
85 MK_STRN const callfunc
86) {
87 OT_OBJ_T errorCode = (OT_OBJ_T ) exception;
88 MK_ERR err = MkErrorFORMAT_1M(expobj);
89
90 if (interp==NULL) interp = amkrt->interp;
91 OT_OBJ_T item;
92 if (errorCode == NULL) {
93 errorCode = Tcl_GetVar2Ex (interp, "errorCode", NULL, TCL_GLOBAL_ONLY);
94 }
95
96//printLngObj(errorCode);
97
98 //Tcl_Eval(interp,"::atlmkkernel::MkErrorC::ProcessStack xxx");
99//printLngObj(Tcl_GetReturnOptions(interp,TCL_ERROR));
100
101 if (
102 errorCode == NULL || // "errorCode" not set
103 Tcl_ListObjIndex (NULL, errorCode, 0, &item) == TCL_ERROR || // index "0" is not in the list "code"
104 strcmp (Tcl_GetString (item), "MkExceptionC") != 0 // error is not from "MkExceptionC"
105 ) {
106 // tcl error
107 MK_STRN errorInfo = Tcl_GetVar (interp, "errorInfo", TCL_GLOBAL_ONLY);
108 if (errorInfo == NULL) errorInfo = "unspecified error...";
109 MkErrorSetC(err,errorInfo,callfunc,-1);
110 } else {
111 // atlmkkernel error
112 if (Tcl_ListObjIndex (NULL, errorCode, 1, &item) == TCL_ERROR) {
113 MkErrorSetV(err, callfunc, -1, "internal error: 'errorCode' return: %s", Tcl_GetStringResult(interp));
114 goto end;
115 }
116
117 MK_OBJ obj = NULL;
118 MkTestClassE flag;
119 if (OT_LNG_OBJECT_IS_3 (item, &obj, &flag)) {
120 switch (flag) {
121 case MkTestClassE_OK : break;
122 case MkTestClassE_NULL : break;
124 MkErrorSetV (err, callfunc, -1, "internal error: '%s' has no 'MkObjectC' type", VAL2STR(item));
125 goto end;
126 }
127 default: {
128 MkErrorSetV (err, callfunc, -1, "internal error: 'MkTestObject' return WRONG num '%d'", flag);
129 goto end;
130 }
131 }
132 } else {
133 MkErrorSetV (err, callfunc, -1, "internal error: '%s' has no 'Object' type", VAL2STR(item));
134 goto end;
135 }
136
137 MK_ERR newerr = MkErr(obj);
138 if (newerr == NULL) {
139 MkErrorSetC (err, "internal error: 'errorCode' has no 'MkExceptionC' type", callfunc, -1);
140 goto end;
141 }
142 // the "ret = ..." is required because of send-1-4a-B-
143 MkErrorSetE(err,newerr);
144
145//printV("err=%p, object=%s, ret=%s\n", err, OT_LNG_NAME_FROM_OBJ(item), MkLogErrorE(ret))
146
147 // need HARD delete MkErrorC -> indirect hard delete with "MkRefDecr" depends on internal MQ-refcount
148 // tclOO does !!NOT!! allow 2 objects with SAME name:
149 // error: can't create object "xxx": command already exists with that name
150 // tclOO MQ object-name has '::<MkErrorE-0xPTR>' as name -> this mean NO object with SAME PTR is allowed !!
151 //OT_OBJECT_DELETE_HARD(VAL2SELF(item));
152 //MkRefDecr_X(err);
153 }
154end:
155 Tcl_ResetResult(interp);
156 return err;
157}
158
159//
160// *********************************************************************************
161//
162
#define MK(n)
#define MkErrorC_ObjNew(nat)
#define NS(n)
#define VAL2STR(val)
#define check_LNG(code)
#define OT_MK_CALL
#define OT_Prefix_ARGS
MOX_OBJ_T OT_OBJ_T
tag: nhi1-release-250425
struct MkErrorS * MK_ERR
class-shortcut for struct MkErrorS *, all shortcut using the XX_YYY syntax (only for public API) …
static bool MkErrCheck(MK_MNGN mng)
check MkErrorS -> MkObjectS::signature …
static MK_ERR MkErr(MK_MNG mng)
cast a unknown-object into an MkErrorS pointer or NULL if not possible
#define MkErrorGetText_0E()
#define MkErrorReset_1(err)
#define MkErrorStackFormat(...)
#define MkErrorSetC(...)
#define MkErrorSetV(...)
#define MkErrorSetE(...)
#define MK_ERROR_PRINT
#define MkErrorFORMAT_1M(m)
#define MkErrorDup(...)
const MK_PTRB * MK_MNGN
const - a managed object pointer, datatype will be checked at runtime
const MK_STRB * MK_STRN
constant string pointer data-type
MK_PTRB * MK_MNG
managed object pointer, datatype will be checked at runtime
MK_PTRB const * MK_EXP
exception object pointer
MK_STRB * MK_STR
string pointer data-type with UTF8 ecoding (string)
signed int MK_I32
4 byte integer data-type
#define MkLogV_2(fmtobj, printfmt,...)
#define MkRefDecr_X(x)
#define MkRefIncr_1X(x)
#define MkThreadLocal
#define OT_LNG_OBJECT_IS_3(objV, obj, flag)
@ MkTestClassE_OK
@ MkTestClassE_INVALID_SIGNATURE
@ MkTestClassE_NULL
The data-type to store and handle the error-condition …
object header …