theKernel 10.0
Loading...
Searching...
No Matches
csmkkernel.MkExceptionC Class Reference

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

+ Inheritance diagram for csmkkernel.MkExceptionC:
+ Collaboration diagram for csmkkernel.MkExceptionC:

Public Member Functions

 MkExceptionC (IntPtr expobj, [CallerMemberName] string callfunc=null, [CallerLineNumber] int callline=-1)
 convert an MkErrorC into a Target-Programming-Language (TPL) exception …
 
 MkExceptionC (SerializationInfo info, StreamingContext sctx)
 
override void GetObjectData (SerializationInfo info, StreamingContext sctx)
 

Static Public Member Functions

static IntPtr Catch (IntPtr mkrt, IntPtr expobj, Exception exception, IntPtr callfunc)
 convert an Target-Programming-Language (TPL) exception into an MkErrorC
 

Detailed Description

C-API: MkExceptionC_C_API - 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 default-error is defined in MkRuntimeS::error_mk.
  • On error the default-error is set to the error-data, the MkErrorE status change to MK_ERROR.
  • The non-C language create a copy from the default-error and throw the copy as MkExceptionC exception.
  • The C language just return the MkErrorE status of the default-error.

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

Definition at line 28 of file MkExceptionC.cs.

Constructor & Destructor Documentation

◆ MkExceptionC() [1/2]

csmkkernel.MkExceptionC.MkExceptionC ( IntPtr expobj,
[CallerMemberName] string callfunc = null,
[CallerLineNumber] int callline = -1 )
inline

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, null = resolve-own-name)
[in]calllinethe number of the line the call take place (e.g. LINE)

Definition at line 39 of file MkExceptionC.cs.

43 : base(Marshal.PtrToStringAnsi(Mk.MkErrorGetText(Mk.MkErrorFORMAT(expobj)))) {
44 IntPtr def = Mk.MkErrorFORMAT(expobj);
45 IntPtr err = Mk.MkErr(expobj);
46 IntPtr rt = Mk.MkRuntimeGetFromObj(err);
47 hdl = err != IntPtr.Zero && err != def ? err : Mk.MkErrorDup(rt,def);
48 mkrt = rt;
49 MkErrorC.StackFull(rt,hdl);
50 Mk.MkRefIncr(hdl);
51 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
52 Mk.MkErrorReset(rt,def,callfunc_cstr,callline,false);
53 Marshal.FreeHGlobal(callfunc_cstr);
54 }
MkErrorC - the class known as err or error is used to create and manage an error message …
Definition MkErrorC.cs:498
static MkErrorE StackFull(IntPtr mkrt, IntPtr hdl)
C#: MkErrorE err.Stack([CallerMemberName]string callfunc = null, [CallerFilePath]string callfile = n...
Definition MkErrorC.cs:101
static IntPtr MkErrorFORMAT(IntPtr fmtobj)

◆ MkExceptionC() [2/2]

csmkkernel.MkExceptionC.MkExceptionC ( SerializationInfo info,
StreamingContext sctx )
inline

Definition at line 56 of file MkExceptionC.cs.

56 {
57 hdl = (IntPtr) info.GetValue("hdl", typeof(IntPtr));
58 }

Member Function Documentation

◆ Catch()

static IntPtr csmkkernel.MkExceptionC.Catch ( IntPtr mkrt,
IntPtr expobj,
Exception exception,
IntPtr callfunc )
inlinestatic

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 C#, if null the global exception object is used
[in]callfunca user-defined postfix to identify the calling-function or the environment (default = name-of-function, null = resolve-own-name)
Returns
the MkErrorC created with data from exception
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)

Definition at line 72 of file MkExceptionC.cs.

77 {
78 IntPtr err = Mk.MkErrorFORMAT(expobj);
79
80 // The exception that is thrown by methods invoked through reflection.
81 if (exception is TargetInvocationException) exception = exception.InnerException;
82 if (exception is MkExceptionC) {
83//Console.Error.WriteLine($">>>>>\n{exception}\n<<<<<");
84 MkExceptionC mqex = (MkExceptionC) exception;
85 Mk.MkErrorSetE (mkrt,err, mqex.hdl);
86 } else {
87//Console.Error.WriteLine("exception=" + exception);
88 IntPtr message_cstr = Marshal.StringToHGlobalAnsi($"{exception.GetType().FullName}: {exception.Message}");
89 Mk.MkErrorSetC (mkrt,err, message_cstr, callfunc, -1);
90 Marshal.FreeHGlobal(message_cstr);
91 var st = new System.Diagnostics.StackTrace(exception, true);
92
93 foreach (var sf in st.GetFrames()) {
94 if (!StackFrameExtensions.HasMethod(sf)) continue;
95//Console.Error.WriteLine("sf=" + sf);
96 var meth = sf.GetMethod();
97 string fn;
98 int ln;
99 if (StackFrameExtensions.HasSource(sf)) {
100 fn = sf.GetFileName();
101 ln = sf.GetFileLineNumber();
102 } else {
103 fn = meth.DeclaringType.Module.Name;
104 ln = -1;
105 }
106 MkErrorC.Stack(mkrt,err,meth.ToString(), fn, ln);
107 if (meth.Name == "ServiceCall") break;
108 }
109 }
110 return err;
111 }
static MkErrorE Stack(IntPtr mkrt, IntPtr hdl, [CallerMemberName]string callfunc=null, [CallerFilePath]string callfile=null, [CallerLineNumber]int callline=-1)
C#: MkErrorE err.Stack([CallerMemberName]string callfunc = null, [CallerFilePath]string callfile = n...
Definition MkErrorC.cs:85
C-API: MkExceptionC_C_API - MkExceptionC - The default-exception of the Programming-Language-Micro-...

◆ GetObjectData()

override void csmkkernel.MkExceptionC.GetObjectData ( SerializationInfo info,
StreamingContext sctx )
inline

Definition at line 65 of file MkExceptionC.cs.

65 {
66 info.AddValue("hdl", hdl);
67 base.GetObjectData (info, sctx);
68 }

The documentation for this class was generated from the following file: