nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
42.18k stars 6.65k forks source link

exit without error message #3948

Closed tesla-cat closed 1 year ago

tesla-cat commented 1 year ago

Description

void handle_message(uWS::WebSocket<false, true, PerSocketData>* ws,
                    string_view msg, uWS::OpCode code) {
    json data = json::parse(msg);

     try {
        OptimizerInput inp = data.get<OptimizerInput>();
    } catch (const exception& e) {
        cerr << e.what() << '\n';
    }

    ws->send(data.dump(), code);
}

Reproduction steps

Expected vs. actual results

expect to see error message

Minimal code example

No response

Error messages

No response

Compiler and operating system

windows, Visual Studio 16

Library version

nlohmann_json/3.11.2

Validation

nlohmann commented 1 year ago

Without knowing what any of the called functions do, there is little I can do. Can you provide a stacktrace?

tesla-cat commented 1 year ago
void handle_message(uWS::WebSocket<false, true, PerSocketData>* ws,
                    string_view msg, uWS::OpCode code) {
    json data = json::parse(msg);

    try {
        OptimizerInput inp = data.get<OptimizerInput>();
    } catch (const exception& e) {
        cerr << e.what() << '\n';
        std::cout << boost::stacktrace::stacktrace();
    }

    ws->send(data.dump(), code);
}
nlohmann commented 1 year ago

Can you set a breakpoint to the line where you call parse and find the last line before the exit?

(This looks like an issue in your setup - the library throws exceptions inherited from std::exception, and so far we never saw an issue.

tesla-cat commented 1 year ago

the exit is caused by OptimizerInput inp = data.get<OptimizerInput>(); because everything works after removing it

nlohmann commented 1 year ago

Can you then debug into it? get does not throw too many exceptions.