Exceptions do not work
BullyWiiPlaza opened this issue · 4 comments
C++ exceptions simply do not work despite choosing e.g. the C++20
standard for compiling. Consider the following simple example:
try {
throw std::runtime_error("Oops");
DEBUG_FUNCTION_LINE("This is never printed\n");
} catch (std::exception &exception) {
DEBUG_FUNCTION_LINE("%s\n", exception.what());
}
I'd expect that the exception is thrown, caught and then the exception text Oops
is printed. Well, what actually happens is that the Wii U softlocks when the exception is thrown. Maschell said exceptions are generally disabled in the Cafe OS kernel but they are very useful for more modern control flow handling.
Is there a possibility that exceptions can be enabled (with wut
) and if not, can it be implemented? I don't have much knowledge in the technicalities involved in doing this. Thank you for any help or information on this.
I don't think the COS kernel is involved in C++ exceptions, as in my experience they end up calling abort
; whereas Cafe writes an exception log and stops running application code immediately.
I do feel like I've done some kind of C++ exception work before - I think it was wrapping abort rather than using a try/catch block though. Judging by your choice of print statements, you're using some kind of middleware library (libgui?) - could you try a minimal example, maybe based on helloworld_cpp? (you'll have to use a revision before bffffdf if you're using the packaged beta9, either will work if you're on a bleeding-edge version)
The DEBUG_FUNCTION_LINE()
is part of logger.h
and is from libutilswut
. But it doesn't matter for the exception issue. I'm working on a Wii U plugin system plugin with the wut
and wups
libraries. I don't think I need to write a hello world program in particular. Just add the following code to whatever and run it:
try {
throw std::runtime_error("Oops");
} catch (std::exception &exception) {
}
Make sure it doesn't get optimized away by the compiler. You'll see that it will soft lock the Wii U when ran but it shouldn't with proper exception support.
Confirmed through other devs testing behind the scenes, apparently this has been broken basically forever (all the way back to 1.0.0-alpha). We're likely missing some newlib syscall or flag in gcc.
Confirmed through other devs testing behind the scenes, apparently this has been broken basically forever (all the way back to 1.0.0-alpha). We're likely missing some newlib syscall or flag in gcc.
Are there any news regarding this? Did someone investigate? I feel like having exceptions is so useful that there should be more than 1 person interested in getting this working, right? Also when working with C++ code and/or libraries causing an exception somewhere by accident/faulty programming will crash with no debugging information which is disappointing and time-consuming to debug.