theKernel 10.0
Loading...
Searching...
No Matches
MkExceptionC_ATL_API

MkExceptionC - The default-exception of the Programming-Language-Micro-Kernel (PLMK)More...

+ Collaboration diagram for MkExceptionC_ATL_API:

Functions

void atlmkkernel_MkExceptionC_Raise (OT_Prefix_ARGS MK_MNGN const expobj, MK_STRN const doc, MK_STRN const callfunc, MK_I32 callline)
 convert an MkErrorC into a Target-Programming-Language (TPL) exception …
 
MK_ERR atlmkkernel_MkExceptionC_Catch (OT_Prefix_ARGS MK_MNG const expobj, MK_EXP const exception, MK_STRN const callfunc)
 convert an Target-Programming-Language (TPL) exception into an MkErrorC
 

Detailed Description

MkExceptionC - The default-exception of the Programming-Language-Micro-Kernel (PLMK)

The Programming-Language-Micro-Kernel (PLMK) provide with MkErrorC a complete error-handling with focus to support the "C" Programming-Language. The support include catch, raise, signal and attributes. In addition every Target-Programming-Language (TPL) add their own error-handling and the purpose of MkExceptionC is to integrate the MkErrorC into the Target-Programming-Language (TPL).

The default-exception MkExceptionC is used to connect the MkErrorC with the Target-Programming-Language (TPL) error-object.

The implementation of an exception depends heavily on the Target-Programming-Language (TPL), starting with no exception at all, for example. C, an exception as a class object, or as an exception as a global attribute.

Attention

Function Documentation

◆ atlmkkernel_MkExceptionC_Catch()

MK_ERR atlmkkernel_MkExceptionC_Catch ( OT_Prefix_ARGS MK_MNG const expobj,
MK_EXP const exception,
MK_STRN const callfunc )

convert an Target-Programming-Language (TPL) exception into an MkErrorC

Parameters
[in]expobjThe LibMsgqueObject used to personalize the exception/error (will be validated first)
[in]exceptionthe exception object from Atl, if "MK_NULL" the global exception object is used
[in]callfunca user-defined postfix to identify the calling-function or the environment (default = name-of-function, "MK_NULL" = resolve-own-name)
Returns
the MkErrorC created with data from exception

Definition at line 81 of file MkExceptionC_atl.c.

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}
#define VAL2STR(val)
MOX_OBJ_T OT_OBJ_T
static MK_ERR MkErr(MK_MNG mng)
cast a unknown-object into an MkErrorS pointer or NULL if not possible
#define MkErrorSetC(...)
#define MkErrorSetV(...)
#define MkErrorSetE(...)
#define MkErrorFORMAT_1M(m)
const MK_STRB * MK_STRN
constant string pointer data-type
#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 …

◆ atlmkkernel_MkExceptionC_Raise()

void atlmkkernel_MkExceptionC_Raise ( OT_Prefix_ARGS MK_MNGN const expobj,
MK_STRN const doc,
MK_STRN const callfunc,
MK_I32 callline )

convert an MkErrorC into a Target-Programming-Language (TPL) exception …

Parameters
[in]expobjThe LibMsgqueObject used to personalize the exception/error (will be validated first)
[in]callfunca user-defined postfix to identify the calling-function or the environment (default = name-of-function, "MK_NULL" = resolve-own-name)
[in]calllinethe number of the line the call take place (e.g. LINE)
[in]docdocumentation string

Definition at line 28 of file MkExceptionC_atl.c.

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}
#define MK(n)
#define MkErrorC_ObjNew(nat)
#define NS(n)
#define check_LNG(code)
#define OT_MK_CALL
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 …
#define MkErrorGetText_0E()
#define MkErrorReset_1(err)
#define MkErrorStackFormat(...)
#define MK_ERROR_PRINT
#define MkErrorDup(...)
MK_STRB * MK_STR
string pointer data-type with UTF8 ecoding (string)
#define MkLogV_2(fmtobj, printfmt,...)
#define MkRefDecr_X(x)
#define MkRefIncr_1X(x)
#define MkThreadLocal