theKernel 10.0
Loading...
Searching...
No Matches
MkExceptionC.cs
Go to the documentation of this file.
1
9/* LABEL-NO */
10using System;
11using System.Threading;
12using System.Reflection;
13using System.Runtime.InteropServices;
14using System.Runtime.CompilerServices;
15using csmkkernel;
16/* LABEL-END */
17
18using System.Runtime.Serialization;
19using System.Diagnostics;
20
21namespace csmkkernel {
22
26
28 public partial class MkExceptionC : Exception
29 {
30 static MkExceptionC() {
31 // init libmkkernel
32 Mk.MkSetup();
33 }
34
35 internal IntPtr hdl = IntPtr.Zero ;
36 internal IntPtr mkrt = IntPtr.Zero ;
37
40 IntPtr expobj,
41 [CallerMemberName] string callfunc = null,
42 [CallerLineNumber] int callline = -1
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 }
55
56 public MkExceptionC(SerializationInfo info, StreamingContext sctx) {
57 hdl = (IntPtr) info.GetValue("hdl", typeof(IntPtr));
58 }
59
61 Mk.MkRefDecr(mkrt,hdl);
62 hdl = IntPtr.Zero;
63 }
64
65 public override void GetObjectData(SerializationInfo info, StreamingContext sctx) {
66 info.AddValue("hdl", hdl);
67 base.GetObjectData (info, sctx);
68 }
69
72 public static IntPtr Catch (
73 IntPtr mkrt,
74 IntPtr expobj,
75 Exception exception,
76 IntPtr callfunc
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 }
112 }
113
116 public class MkSignatureExceptionC : Exception
117 {
118 public MkSignatureExceptionC(string text = "") : base("signature ERROR: " + text) {
119 }
120 }
121
123 public class MkConstructorNullExceptionC : Exception
124 {
125 public MkConstructorNullExceptionC(string text = "") :
126 base("NULL ERROR: the constructor '" + text + "' got a NULL pointer") {
127 }
128 }
129
131 public class MkReferenceNullExceptionC : Exception
132 {
133 public MkReferenceNullExceptionC(string text = "") :
134 base("NULL REFERENCE ERROR: the argument '" + text + "' got a NULL pointer") {
135 }
136 }
137
139 public class MkInitError : Exception
140 {
141 public MkInitError(string text = "") :
142 base("'" + text + "' constructor return 'NULL' pointer") {
143 }
144 }
145
147 public class MkInitSoftError : Exception
148 {
149 public MkInitSoftError(string text = "") :
150 base("'" + text + "' soft constructor return 'NULL' pointer") {
151 }
152 }
153
155 public class MkCallbackNotFoundError : Exception {
156 public MkCallbackNotFoundError(Type cls, string dlg, String cbS) :
157 base("unable to find callback '" + cbS + "' in class '" + cls.Name + "' provide delegate '" + dlg + "'") {
158 }
159 }
160 // exception classes
162
164
165} // END - namespace "csmkkernel"
166
167
MkCallbackNotFoundError(Type cls, string dlg, String cbS)
MkErrorC - the class known as err or error is used to create and manage an error message …
Definition MkErrorC.cs:498
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
static MkErrorE StackFull(IntPtr mkrt, IntPtr hdl)
C#: MkErrorE err.Stack([CallerMemberName]string callfunc = null, [CallerFilePath]string callfile = n...
Definition MkErrorC.cs:101
C-API: MkExceptionC_C_API - MkExceptionC - The default-exception of the Programming-Language-Micro-...
MkExceptionC(IntPtr expobj, [CallerMemberName] string callfunc=null, [CallerLineNumber] int callline=-1)
convert an MkErrorC into a Target-Programming-Language (TPL) exception …
static IntPtr Catch(IntPtr mkrt, IntPtr expobj, Exception exception, IntPtr callfunc)
convert an Target-Programming-Language (TPL) exception into an MkErrorC …
MkExceptionC(SerializationInfo info, StreamingContext sctx)
override void GetObjectData(SerializationInfo info, StreamingContext sctx)
MkInitError(string text="")
MkInitSoftError(string text="")
static IntPtr MkErrorFORMAT(IntPtr fmtobj)
MK_STRN MkErrorGetText(MK_ERRN const err)
get the MkErrorS::text …
MK_ERR MkErrorFORMAT(MK_OBJN fmtobj)
system-error-format - format and return the default-error …