Cosmos icon indicating copy to clipboard operation
Cosmos copied to clipboard

Try Catch not working if exception thrown in overriden abstract method

Open GoldenretriverYT opened this issue 2 years ago • 8 comments

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

GoldenretriverYT avatar Jun 25 '22 16:06 GoldenretriverYT

when i use try catch, it sometimes works sometimes it crashes cosmos, not os.

AsertCreator avatar Aug 31 '22 12:08 AsertCreator

Yeah it does work SOMETIMES for me too, but sometimes the OS then just freezes or crashes

GoldenretriverYT avatar Aug 31 '22 15:08 GoldenretriverYT

that's weird, it never does that to me it actually calls the BSOD function i have so yeah, idk what happened

9xbt avatar Dec 20 '22 20:12 9xbt

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.

AudioTore avatar Feb 26 '23 13:02 AudioTore

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.

GoldenretriverYT avatar Feb 26 '23 14:02 GoldenretriverYT

Can you just try printing out the ex variable then?

AudioTore avatar Feb 26 '23 16:02 AudioTore

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.

GoldenretriverYT avatar Feb 26 '23 16:02 GoldenretriverYT

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

GoldenretriverYT avatar Mar 22 '23 20:03 GoldenretriverYT