Qt for WebAssembly and exceptions
Unsolved
Qt for WebAssembly
-
Hi I have been exploring with Qt for WebAssembly to help me learn more about the WebAssembly platform.
One thing that I cannot for the life of me figure out is how to enable exceptions using Qt's infrastructure?
Example project:
# CMakeLists.txt cmake_minimum_required(VERSION 3.22) project(learnWebAssembly VERSION 0.1.0) include(CTest) enable_testing() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) find_package(Qt6 6.4.0 REQUIRED COMPONENTS Core Qml Gui CMAKE_FIND_ROOT_PATH_BOTH) add_compile_options(-fexceptions -sNO_DISABLE_EXCEPTION_CATCHING) add_link_options( "SHELL:-fexceptions" "SHELL:-sLLD_REPORT_UNDEFINED" "SHELL:-sNO_DISABLE_EXCEPTION_CATCHING" "SHELL:-sLIBRARY_DEBUG=1" "SHELL:-sSYSCALL_DEBUG=1" # "SHELL:-sFS_LOG=1" "SHELL:-sSOCKET_DEBUG" ) qt_add_executable(exceptions_example exceptions-example.cpp) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) include(CPack)
// example-exceptions.cpp #include <stdio.h> int main() { try { puts("throw..."); throw 1; puts("(never reached)"); } catch(...) { puts("catch!"); } return 0; }
When I compile this using CMake I get the error:
Exception catching is disabled, this exception cannot be caught. Compile with -sNO_DISABLE_EXCEPTION_CATCHING or -sEXCEPTION_CATCHING_ALLOWED=[..] to catch.
but when I compile this file according to the webassembly documentation I can catch exceptions according to the docs? https://emscripten.org/docs/porting/exceptions.html?highlight=fexception
Outstanding questions:
If I use a release build of Qt for WebAssembly does that override any of my explicit exception handling flags set at compile time?
Do I need to use a debug build of Qt for WebAssembly then to catch exceptions?Thanks for taking the time to read this!