I read this and find out it's important to handle exceptions, i use nlohmann::json
(from github) and nearly in most of my member functions is use nlohmann::json::parse
and nlohmann::json::dump
which make a chance to throw exceptions if the input has a problem.
So I need to handle those chance of throwing exception something like this:
bool my_class::function(const std::string& input) const
try
{
using namespace nlohmann;
const auto result = json::parse(input);
const auto name = result["name"].dump();
/* and ... */
}
catch (const std::exception& e)
{
/* handle exception */
}
But i want to know which line of the code throw exception, so if i write something like this:
bool my_class::function(const std::string& input) const
{
using namespace nlohmann;
try
{
const auto result = json::parse(input);
}
catch(const std::exception& e)
{
/* handle exception */
}
try
{
const auto name = result["name"].dump();
}
catch(const std::exception& e)
{
/* handle exception */
}
/* and ... */
}
It left me with thousands of try-catch blocks. It's a better why to handle exception ?