-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
program still abort() or exit() with try catch #1541
Comments
Yes, the program should not terminate after catching an exception. What kind of exception did you catch before termination? Do you have a working example? |
I catch the exception parse_error, which means the client send a bad json string so that the proxy cannot decode the json messages. But I don't want the proxy make a assertion to interrupt its executing, it should be continuing to receive next string message. |
What does the assertion say? |
like below: [json.exception.parse_error.101] parse error at line 1, column 84: syntax error while parsing object - une [json.exception.parse_error.101] parse error at line 1, column 84: syntax error while parsing object - une terminate called after throwing an instance of 'nlohmann::detail::type_error' |
The last exception should not come from the parser. Can you check your debugger where it was thrown? |
yeah, it comes from the message decode, inline void to_json(nlohmann::json& j, const TapAPIOrderInfo* p) { and a null pointer maybe assign to the json. |
Ok, so that json j; // null value
std::string s = j; // throws type_error |
got it. but how to deal with parse_error? |
What do you mean? You already catch it and continue? I am assuming the code of #1541 (comment). |
yeah, but I don't know why the program still exit when the exception occurs. |
You need to share more information on your code. Originally, you reported a |
Could you try to catch |
i encounter same issue in android platform. same code is fine in mac platform.
this is crash stack in android platform
|
this is my mac result:
Process finished with exit code 0 |
@nlohmann please |
Which exception crashes the program on Android? |
crash stack:
|
if you find out the result, please tell me as soon as possible, thank you @nlohmann |
Can you try to also catch |
i tried,but useless. std::exception or ... all tried. program still exit |
you can try this code on Android platform. program will exit. mac/ios platform is work well |
i find out the reason. i used custom openssl in my project,i linked my libcrypto.so,i don't known why json library use my libcrypto.so |
It does not, I can guarantee. |
@cosmos33: As Nlohmann stated, JSON library doesn't have any dependency on libcrypto. Having this issue with the sample code you provided, which is very simple, indicates a toolchain/linking issue. You can try the following steps to pinpoint the root cause:
#include <iostream>
#include <vector>
int main() {
try {
std::cout << "Throwing an integer exception...\n";
throw 42;
} catch (int i) {
std::cout << " the integer exception was caught, with value: " << i << '\n';
}
try {
std::cout << "Creating a vector of size 5... \n";
std::vector<int> v(5);
std::cout << "Accessing the 11th element of the vector...\n";
std::cout << v.at(10); // vector::at() throws std::out_of_range
} catch (const std::exception& e) { // caught by reference to base
std::cout << " a standard exception was caught, with message '"
<< e.what() << "'\n";
}
} Make sure you have adequate flags in the build scripts to enable exception handling for Android NDK. If you were still getting Abort signal, this could be helpful: android/ndk#289
|
` set(LIB_OPENSSL_INCLUDE ${THIRD_PARTY_BASE_PATH}/openssl/android/include/) target_link_libraries(native-lib ` i link my crypto.so, parse json will crash in my mmcrypto.so. |
Unfortunately I don't have the knowledge nor the environment for building Android projects. You should try the steps mentioned in #1541 (comment) which might help us to figure out the problem. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi @mslovy , Any resolution for this issue. |
I use try catch like below:
I expect the program continue to be executed and then processs next msg. but after print out the error message such as parse error. The program abort() or exit(), can anyone give some suggestion about this.
The text was updated successfully, but these errors were encountered: