Closed paulocoutinhox closed 1 year ago
You're catching by non-const reference. What if you catch by const reference or by value?
I see xplpc.wasm
in the call stack. Is this a WebAssembly build?
Hi @gregmarr,
Yes, it is a WebAssembly build.
I tried in a simple file in my local machine without WASM context and it compiles and run without problems:
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main(int argc, char const *argv[])
{
try
{
//auto j = json::parse(R"({"value": "demo"})");
auto j = json::parse(R"(!)");
std::cout << j << std::endl;
//auto value = j["value"].get<std::string>();
auto value = j["value"].template get<std::string>();
std::cout << "VALUE: " << value << std::endl;
}
catch (std::exception &e)
{
std::cout << "ERROR: " << e.what() << std::endl;
}
return EXIT_SUCCESS;
}
// To compile with gcc:
// 1 - Need header files from https://github.com/nlohmann/json inside folder "include"
// 2 - g++ -std=c++17 -Iinclude main.cpp -o json
Can be a problem with WebAssembly only?
Thanks.
The exceptions of the library inherit from std::exception (see https://json.nlohmann.me/home/exceptions/), so the code looks fine. Very strange.
Are you using Emscripten? https://emscripten.org/docs/porting/exceptions.html
Hi,
Yes, im using.
Im trying to compile a simple with it and always throw error.
I tried all emscripten compile flags.
Solved now.
The problem is that i need use the flags on CXX_FLAGS too:
set(XPLPC_WASM_LINKER_FLAGS "--bind -sMALLOC=emmalloc -sWASM_BIGINT=1 -sALLOW_MEMORY_GROWTH=1 -fwasm-exceptions -sMODULARIZE=1 -sEXPORT_ES6=1")
set(XPLPC_WASM_COMPILER_FLAGS "-fwasm-exceptions")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${XPLPC_WASM_LINKER_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XPLPC_WASM_COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${XPLPC_WASM_COMPILER_FLAGS}")
Thanks.
You're welcome. Glad you were able to sort it out.
Description
Even though my code is inside a try it is throwing exception and stopping the program.
Reproduction steps
Only need call the example function:
Expected vs. actual results
Excepted is return the default value when exception happen. Actual result is crashing.
Minimal code example