Skip to content
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

Closed
mslovy opened this issue Mar 23, 2019 · 28 comments
Closed

program still abort() or exit() with try catch #1541

mslovy opened this issue Mar 23, 2019 · 28 comments
Labels
kind: question state: needs more info the author of the issue needs to provide more details state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated

Comments

@mslovy
Copy link

mslovy commented Mar 23, 2019

I use try catch like below:

while(true) {
          try {
              jsonMsg = json::parse(msg);
          }
          catch(exception& e) {
              ldout << "error message: " << e.what() << endl;
              continue;
          }
}

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.

@nlohmann
Copy link
Owner

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?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Mar 23, 2019
@mslovy
Copy link
Author

mslovy commented Mar 24, 2019

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.

@nlohmann
Copy link
Owner

What does the assertion say?

@mslovy
Copy link
Author

mslovy commented Mar 24, 2019

like below:

[json.exception.parse_error.101] parse error at line 1, column 84: syntax error while parsing object - une
xpected end of input; expected '}'

[json.exception.parse_error.101] parse error at line 1, column 84: syntax error while parsing object - une
xpected end of input; expected '}'

terminate called after throwing an instance of 'nlohmann::detail::type_error'
what(): [json.exception.type_error.302] type must be string, but is null
Aborted

@nlohmann
Copy link
Owner

The last exception should not come from the parser. Can you check your debugger where it was thrown?

@mslovy
Copy link
Author

mslovy commented Mar 24, 2019

yeah, it comes from the message decode,

inline void to_json(nlohmann::json& j, const TapAPIOrderInfo* p) {
17 j = nlohmann::json{
18 {"AccountNo", p->AccountNo},
19 {"ExchangeNo", p->ExchangeNo},
20 {"CommodityType", p->CommodityType},
21 {"CommodityNo", p->CommodityNo},
22 {"ContractNo", p->ContractNo},
23 {"StrikePrice", p->StrikePrice},
24 {"CallOrPutFlag", p->CallOrPutFlag},
25 {"ContractNo2", p->ContractNo2},
26 {"StrikePrice2", p->StrikePrice2},
27 {"CallOrPutFlag2", p->CallOrPutFlag2},
28 {"OrderType", p->OrderType},
29 {"OrderSource", p->OrderSource},
30 {"TimeInForce", p->TimeInForce},
31 {"ExpireTime", p->ExpireTime},
32 {"IsRiskOrder", p->IsRiskOrder}
}

and a null pointer maybe assign to the json.

@nlohmann
Copy link
Owner

Ok, so that nlohmann::detail::type_error exception is not from the parser. The error message type must be string, but is null means that you try to read a JSON value of type null where a string is expected. This is usually during a from_json conversion. Something like

json j; // null value
std::string s = j; // throws type_error

@mslovy
Copy link
Author

mslovy commented Mar 25, 2019

got it. but how to deal with parse_error?

@nlohmann
Copy link
Owner

nlohmann commented Mar 25, 2019

What do you mean? You already catch it and continue? I am assuming the code of #1541 (comment).

@mslovy
Copy link
Author

mslovy commented Mar 26, 2019

yeah, but I don't know why the program still exit when the exception occurs.

@nlohmann
Copy link
Owner

You need to share more information on your code. Originally, you reported a nlohmann::detail::type_error exception, which was thrown outside the code you provided in #1541 (comment).

@nlohmann
Copy link
Owner

Could you try to catch std::exception &e and output e.what()?

@cosmos33
Copy link

i encounter same issue in android platform. same code is fine in mac platform.
this is my code :

try {
std::string testStr = "sfasd23sfwefws";
mJsonObj = nlohmann::json::parse(testStr);
} catch (nlohmann::detail::parse_error &error) {
std::cout << "parse_error" << std::endl;
} catch (nlohmann::detail::exception &error) {
std::cout << "exception" << std::endl;
} catch (std::overflow_error &error) {
std::cout << "overflow_error" << std::endl;
}

this is crash stack in android platform

2019-04-20 14:08:29.584 32581-32581/? A/DEBUG: backtrace:
2019-04-20 14:08:29.584 32581-32581/? A/DEBUG: #00 pc 0001ce36 /system/lib/libc.so (abort+58)
2019-04-20 14:08:29.584 32581-32581/? A/DEBUG: #1 pc 0007d1d9 /system/lib/libc.so (ifree+880)
2019-04-20 14:08:29.584 32581-32581/? A/DEBUG: #2 pc 0007d2f7 /system/lib/libc.so (je_free+70)
2019-04-20 14:08:29.584 32581-32581/? A/DEBUG: #3 pc 0007ba1b /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libc++_shared.so (std::overflow_error::~overflow_error()+50)
2019-04-20 14:08:29.584 32581-32581/? A/DEBUG: #4 pc 000da765 /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libmmdns.so (nlohmann::detail::exception::~exception()+32)
2019-04-20 14:08:29.584 32581-32581/? A/DEBUG: #5 pc 000e48a9 /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libmmdns.so (nlohmann::detail::parse_error::~parse_error()+16)
2019-04-20 14:08:29.584 32581-32581/? A/DEBUG: #6 pc 000e52ef /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libmmdns.so (bool nlohmann::detail::parser<nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator>, bool, long long, unsigned long long, double, std::__ndk1::allocator, nlohmann::adl_serializer>>::sax_parse_internal<nlohmann::detail::json_sax_dom_parser<nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, std::__ndk1::
2019-04-20 14:08:29.584 32581-32581/? A/DEBUG: #7 pc 000e0107 /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libmmdns.so (nlohmann::detail::parser<nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator>, bool, long long, unsigned long long, double, std::__ndk1::allocator, nlohmann::adl_serializer>>::parse(bool, nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, std::__ndk1::basic_string<char, std::__ndk1::char_traits,
2019-04-20 14:08:29.584 32581-32581/? A/DEBUG: #8 pc 000ded55 /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libmmdns.so (nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator>, bool, long long, unsigned long long, double, std::__ndk1::allocator, nlohmann::adl_serializer>::parse(nlohmann::detail::input_adapter&&, std::__ndk1::function<bool (int, nlohmann::detail::parser<nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, st
2019-04-20 14:08:29.585 32581-32581/? A/DEBUG: #9 pc 000fbb6f /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libmmdns.so (mmdns::MMDNSJson::MMDNSJson(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&)+434)
2019-04-20 14:08:29.585 32581-32581/? A/DEBUG: #10 pc 000fb7d3 /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libmmdns.so (ZNSt6__ndk110shared_ptrIN5mmdns9MMDNSJsonEE11make_sharedIJRNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEES3_DpOT+590)
2019-04-20 14:08:29.585 32581-32581/? A/DEBUG: #11 pc 00122f4d /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libmmdns.so (mmdns::MMDNSHttpServerHandle::RequestHttpDNS(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&)+9468)
2019-04-20 14:08:29.585 32581-32581/? A/DEBUG: #12 pc 00124ba1 /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libmmdns.so (mmdns::MMDNSHttpServerHandle::GetCheckResult(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&)+72)
2019-04-20 14:08:29.585 32581-32581/? A/DEBUG: #13 pc 0012816f /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libmmdns.so (mmdns::MMDNSServer::RunCheckTask()+1422)
2019-04-20 14:08:29.585 32581-32581/? A/DEBUG: #14 pc 0012d641 /data/app/com.immomo.momo.dev21-xzhU7rJM3enl9mn6NHEkyg==/lib/arm/libmmdns.so (ZNSt6__ndk114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEMN5mmdns11MMDNSServerEFvvEPS8_EEEEEPvSD+248)

@cosmos33
Copy link

this is my mac result:

/Users/wangduanqing/Documents/Work/mmdns/common/cmake-build-debug/mmdns
project init
parse_error
project end

Process finished with exit code 0

@cosmos33
Copy link

@nlohmann please

@nlohmann
Copy link
Owner

Which exception crashes the program on Android?

@cosmos33
Copy link

crash stack:

2019-04-20 15:32:38.681 13130-13130/com.immomo.momo.dev21 A/libc: Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 13130 (momo.momo.dev21), pid 13130 (momo.momo.dev21)
2019-04-20 15:32:38.750 13162-13162/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2019-04-20 15:32:38.750 13162-13162/? A/DEBUG: Build fingerprint: 'OnePlus/OnePlus6T/OnePlus6T:9/PKQ1.180716.001/1901061800:user/release-keys'
2019-04-20 15:32:38.750 13162-13162/? A/DEBUG: Revision: '0'
2019-04-20 15:32:38.750 13162-13162/? A/DEBUG: ABI: 'arm'
2019-04-20 15:32:38.750 13162-13162/? A/DEBUG: pid: 13130, tid: 13130, name: momo.momo.dev21 >>> com.immomo.momo.dev21 <<<
2019-04-20 15:32:38.750 13162-13162/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
2019-04-20 15:32:38.750 13162-13162/? A/DEBUG: Abort message: 'Invalid address 0xffce5fd8 passed to free: value not allocated'
2019-04-20 15:32:38.750 13162-13162/? A/DEBUG: r0 00000000 r1 0000334a r2 00000006 r3 00000008
2019-04-20 15:32:38.750 13162-13162/? A/DEBUG: r4 0000334a r5 0000334a r6 ffce561c r7 0000010c
2019-04-20 15:32:38.750 13162-13162/? A/DEBUG: r8 ed613208 r9 eca619e0 r10 70945629 r11 ed648000
2019-04-20 15:32:38.750 13162-13162/? A/DEBUG: ip ffce55b8 sp ffce5608 lr f046ffe9 pc f0467e36
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: backtrace:
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #00 pc 0001ce36 /system/lib/libc.so (abort+58)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #1 pc 0007d1d9 /system/lib/libc.so (ifree+880)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #2 pc 0007d2f7 /system/lib/libc.so (je_free+70)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #3 pc 0007ba1b /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libc++_shared.so (std::overflow_error::~overflow_error()+50)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #4 pc 000da765 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (nlohmann::detail::exception::~exception()+32)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #5 pc 000e48a9 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (nlohmann::detail::parse_error::~parse_error()+16)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #6 pc 000e52ef /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (bool nlohmann::detail::parser<nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator>, bool, long long, unsigned long long, double, std::__ndk1::allocator, nlohmann::adl_serializer>>::sax_parse_internal<nlohmann::detail::json_sax_dom_parser<nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, std::__ndk1::
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #7 pc 000e0107 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (nlohmann::detail::parser<nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator>, bool, long long, unsigned long long, double, std::__ndk1::allocator, nlohmann::adl_serializer>>::parse(bool, nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, std::__ndk1::basic_string<char, std::__ndk1::char_traits,
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #8 pc 000ded55 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator>, bool, long long, unsigned long long, double, std::__ndk1::allocator, nlohmann::adl_serializer>::parse(nlohmann::detail::input_adapter&&, std::__ndk1::function<bool (int, nlohmann::detail::parser<nlohmann::basic_json<std::__ndk1::map, std::__ndk1::vector, st
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #9 pc 000fbadf /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (mmdns::MMDNSJson::MMDNSJson(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&)+290)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #10 pc 000fb7d3 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (ZNSt6__ndk110shared_ptrIN5mmdns9MMDNSJsonEE11make_sharedIJRNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEES3_DpOT+590)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #11 pc 000fa94d /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (mmdns::MMDNSFileUtil::MMDNSFileUtil(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator>)+200)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #12 pc 0011e163 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (ZNSt6__ndk110shared_ptrIN5mmdns13MMDNSFileUtilEE11make_sharedIJRKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEES3_DpOT+610)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #13 pc 0011d92d /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (mmdns::MMDNSDataCache::MMDNSDataCache(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&)+144)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #14 pc 0011d55f /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (ZNSt6__ndk110shared_ptrIN5mmdns14MMDNSDataCacheEE11make_sharedIJRNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEES3_DpOT+586)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #15 pc 00126f7b /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (mmdns::MMDNSServer::MMDNSServer()+634)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #16 pc 000f937d /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (_ZNSt6__ndk122__compressed_pair_elemIN5mmdns11MMDNSServerELi1ELb0EEC2Ev+16)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #17 pc 000f9019 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (ZNSt6__ndk110shared_ptrIN5mmdns11MMDNSServerEE11make_sharedIJEEES3_DpOT+364)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #18 pc 000a2571 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (mmdns::MMDNSHostManager::MMDNSHostManager()+60)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #19 pc 00083f05 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (_ZNSt6__ndk122__compressed_pair_elemIN5mmdns16MMDNSHostManagerELi1ELb0EEC2Ev+16)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #20 pc 00083ba1 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (ZNSt6__ndk110shared_ptrIN5mmdns16MMDNSHostManagerEE11make_sharedIJEEES3_DpOT+364)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #21 pc 00082efb /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (mmdns::MMDNSManagerSingleton::SetDNSConfig(std::__ndk1::shared_ptrmmdns::IMMDNSConfig)+690)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #22 pc 00083075 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (mmdns::MMDNSManagerSingleton::InitSDK(std::__ndk1::shared_ptrmmdns::IMMDNSConfig)+168)
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #23 pc 000831bd /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (mmdns::MMDNSManagerSingleton::InitSDK(std::__ndk1::shared_ptrmmdns::IMMDNSConfig, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&, std::__ndk1::basic_str
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #24 pc 0013a463 /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (mmdns::MMDNSManager::InitSDK(std::__ndk1::shared_ptrmmdns::IMMDNSConfig, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator> const&, std::__ndk1::basic_string<char,
2019-04-20 15:32:38.879 13162-13162/? A/DEBUG: #25 pc 00078a3b /data/app/com.immomo.momo.dev21-lO8wpSoQn6OEerkVq3craw==/lib/arm/libmmdns.so (Java_com_immomo_mmdns_MDDNSEntrance_nativeInitDNSConfig+398)
@nlohmann

@cosmos33
Copy link

if you find out the result, please tell me as soon as possible, thank you @nlohmann

@nlohmann
Copy link
Owner

Can you try to also catch std::exception?� There may be an additional exception thrown.

@cosmos33
Copy link

i tried,but useless. std::exception or ... all tried. program still exit

@cosmos33
Copy link

std::string testStr = "asdfa";
try {
nlohmann::json::parse(testStr.c_str());
} catch (std::exception &exception) {
std::cout << "exception" << std::endl;
} catch (std::runtime_error &error) {
std::cout << "error" << std::endl;
} catch (...) {
std::cout << "any" << std::endl;
}

you can try this code on Android platform. program will exit. mac/ios platform is work well

@cosmos33
Copy link

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

@nlohmann
Copy link
Owner

It does not, I can guarantee.

@nickaein
Copy link
Contributor

nickaein commented Apr 26, 2019

@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:

  1. Create an empty C++ project without any library/dependency and try some simple exception handling codes, like (take from this page):
#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

  1. Include the JSON library in the above project and try the sample code you have already provided.

  2. Use the original openssl/libcrypto versions instead of the customized ones. An overlooked inconsistency in the linked libaray and the headers could lead to weird memory corruptions.

@cosmos33
Copy link

`
add_library(mmcrypto SHARED IMPORTED)
set_target_properties(mmcrypto PROPERTIES IMPORTED_LOCATION
${THIRD_PARTY_BASE_PATH}/openssl/android/lib/libmmcrypto.so)

set(LIB_OPENSSL_INCLUDE ${THIRD_PARTY_BASE_PATH}/openssl/android/include/)

target_link_libraries(native-lib
mmcrypto
android
${log-lib}
-lz
)

`

i link my crypto.so, parse json will crash in my mmcrypto.so.
very wicked! you can have a try

android demo

@nickaein
Copy link
Contributor

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.

@stale
Copy link

stale bot commented May 29, 2019

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.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label May 29, 2019
@mslovy mslovy closed this as completed May 30, 2019
@hari269it
Copy link

Hi @mslovy , Any resolution for this issue.
I am facing a similar problem in catching exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question state: needs more info the author of the issue needs to provide more details state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

No branches or pull requests

5 participants