Cosmos
Cosmos copied to clipboard
Try Catch not working if exception thrown in overriden abstract method
Area of Cosmos - What area of Cosmos are we dealing with?
Runtime
Expected Behaviour - What do you think that should happen?
The catch block should be called in case of an exception
Actual Behaviour - What unexpectedly happens?
The OS just crashes
Reproduction - How did you get this error to appear?
So for example, take this Run Method:
protected override void Run() {
try {
ProcessManager.StartProcess(new Process(new TaskbarApp()));
while (true) {
foreach (Process proc in ProcessManager.GetProcesses()) {
proc.app.Update();
}
graphics.RenderFrame();
frameCounter++;
if(previousSecond != RTC.Second) {
previousSecond = RTC.Second;
FramesPerSecond = frameCounter;
frameCounter = 0;
}
}
}catch(Exception ex) {
mDebugger.SendMessage("exception", ex.Message);
Panic.KernelPanic("GENERIC_RunningKernel", ex);
}
}
Now imagine, that StartProcess adds the process to a list. Now, if the list is uninitiliazed, the OS will crash and the catch block will not be executed. It might be worth noting that ProcessManager is a static class, however that shouldn't really matter.
Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)?
DevKit Commit https://github.com/CosmosOS/Cosmos/commit/d64e68add45ef95c4163e79407fe8f762b7bb5f3
when i use try catch, it sometimes works sometimes it crashes cosmos, not os.
Yeah it does work SOMETIMES for me too, but sometimes the OS then just freezes or crashes
that's weird, it never does that to me it actually calls the BSOD function i have so yeah, idk what happened
Not sure if this is too late but I believe on the (catch) line you have to put a "Console.ReadKey();" Thats because when something goes wrong cosmos resorts to catch and executes all the code in their and after that Cosmos Doesn't know what to do so it now resorts to crashing. If you put a Console.ReadKey(); it will give you time to read the error message and see whats going On.
Not sure if this is too late but I believe on the (catch) line you have to put a "Console.ReadKey();" Thats because when something goes wrong cosmos resorts to catch and executes all the code in their and after that Cosmos Doesn't know what to do so it now resorts to crashing. If you put a Console.ReadKey(); it will give you time to read the error message and see whats going On.
Has absolutely nothing to do with this, it does not execute the code at all. My kernel panic screen already halts with a loop. And debugger messages are also not sent, which means that it never executes this.
Can you just try printing out the ex variable then?
What do you mean? Where? It is not executed. Thats a fact. Nothing will change that. I could literally change it to send "a" to the debugger and it wont execute.
What I just noticed, this seems to only happen if your error occurs within an overriden abstract method. Apart from that, try/catch works perfectly fine.
Also, without using the debugger, the crash message is EInvalidOpcode