theKernel 10.0
Loading...
Searching...
No Matches
MkExceptionC_tcl.c
Go to the documentation of this file.
1
9/* LABEL-NO */
10
11#define META_FILE_NAME "MkExceptionC_tcl.c"
12
13#include "LibMkKernel_tcl.h"
14#include "mk_check_tcl.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)(MK_RT_CALL interp, 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) (MK_RT_CALL interp, newerr);
57 in_duty = false;
58
59 if (tclErrObj == NULL) {
60 Tcl_SetResult(interp, "WARNING: failed to create an error-object", TCL_STATIC);
61 MkLogV_2(MK_ERROR_PRINT, "%s\n", Tcl_GetStringResult(interp));
62 return;
63 }
64
65//printV("err=%p, object=%s\n", err, OT_LNG_NAME_FROM_OBJ(tclErrObj))
66
67 OT_OBJ_T lst = Tcl_NewObj();
68 check_LNG(Tcl_ListObjAppendElement(interp,lst,RG(MkExceptionC))) goto error;
69 check_LNG(Tcl_ListObjAppendElement(interp,lst,tclErrObj)) goto error;
70 Tcl_SetObjErrorCode(interp,lst);
71 Tcl_SetVar2Ex(interp,"errorCode",NULL,lst,TCL_GLOBAL_ONLY);
72 Tcl_SetResult(interp, (MK_STR) MkErrorGetText_0E(), TCL_VOLATILE);
73
74 MkErrorReset_1(err);
75error:
76 return;
77}
78
80MK_ERR MK(MkExceptionC_Catch) (
82 MK_MNG const expobj,
83 MK_EXP const exception,
84 MK_STRN const callfunc
85) {
86 OT_OBJ_T errorCode = (OT_OBJ_T ) exception;
87 MK_ERR err = MkErrorFORMAT_1M(expobj);
88
89 if (interp==NULL) interp = (OT_ENV_T const) MK_RT_REF.mkThreadData.ptr;
90 OT_OBJ_T item;
91 if (errorCode == NULL) {
92 errorCode = Tcl_GetVar2Ex (interp, "errorCode", NULL, TCL_GLOBAL_ONLY);
93 }
94
95 //Tcl_Eval(interp,"::tclmkkernel::MkErrorC::ProcessStack xxx");
96 //printLngObj(Tcl_GetReturnOptions(interp,TCL_ERROR));
97
98 if (
99 errorCode == NULL || // "errorCode" not set
100 Tcl_ListObjIndex (NULL, errorCode, 0, &item) == TCL_ERROR || // index "0" is not in the list "code"
101 strcmp (Tcl_GetString (item), "MkExceptionC") != 0 // error is not from "MkExceptionC"
102 ) {
103 // tcl error
104 MK_STRN errorInfo = Tcl_GetVar (interp, "errorInfo", TCL_GLOBAL_ONLY);
105 if (errorInfo == NULL) errorInfo = "unspecified error...";
106 MkErrorSetC(err,errorInfo,callfunc,-1);
107 } else {
108 // tclmkkernel error
109 if (Tcl_ListObjIndex (NULL, errorCode, 1, &item) == TCL_ERROR) {
110 MkErrorSetV(err, callfunc, -1, "internal error: 'errorCode' return: %s", Tcl_GetStringResult(interp));
111 goto end;
112 }
113
114 MK_OBJ obj = NULL;
115 MkTestClassE flag;
116 if (OT_LNG_OBJECT_IS_3 (item, &obj, &flag)) {
117 switch (flag) {
118 case MkTestClassE_OK : break;
119 case MkTestClassE_NULL : break;
121 MkErrorSetV (err, callfunc, -1, "internal error: '%s' has no 'MkObjectC' type", VAL2STR(item));
122 goto end;
123 }
124 default: {
125 MkErrorSetC (err, "internal error: 'MkTestObject' return WRONG num", callfunc, -1);
126 goto end;
127 }
128 }
129 } else {
130 MkErrorSetV (err, callfunc, -1, "internal error: '%s' has no 'Object' type", VAL2STR(item));
131 goto end;
132 }
133
134 MK_ERR newerr = MkErr(obj);
135 if (newerr == NULL) {
136 MkErrorSetC (err, "internal error: 'errorCode' has no 'MkExceptionC' type", callfunc, -1);
137 goto end;
138 }
139 // the "ret = ..." is required because of send-1-4a-B-
140 MkErrorSetE(err,newerr);
141
142//printV("err=%p, object=%s, ret=%s\n", err, OT_LNG_NAME_FROM_OBJ(item), MkLogErrorE(ret))
143
144 // need HARD delete MkErrorC -> indirect hard delete with "MkRefDecr" depends on internal MQ-refcount
145 // tclOO does !!NOT!! allow 2 objects with SAME name:
146 // error: can't create object "xxx": command already exists with that name
147 // tclOO MQ object-name has '::<MkErrorE-0xPTR>' as name -> this mean NO object with SAME PTR is allowed !!
148 //OT_OBJECT_DELETE_HARD(VAL2SELF(item));
149 //MkRefDecr(err);
150 }
151end:
152 Tcl_ResetResult(interp);
153 return err;
154}
155
156//
157// *********************************************************************************
158//
159
tag: nhi1-release-250425
#define MK(n)
#define VAL2STR(obj)
#define NS(n)
#define check_LNG(code)
#define RG(_key)
Tcl_Interp * OT_ENV_T
#define OT_Prefix_ARGS
Tcl_Obj * OT_OBJ_T
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 MK_RT_CALL
#define MK_RT_REF
#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 …