Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Qt for WebAssembly and exceptions
Forum Updated to NodeBB v4.3 + New Features

Qt for WebAssembly and exceptions

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
1 Posts 1 Posters 395 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jborys
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved