I was reading through your examples I noticed your parse error example
try {
json::parse(message);
} catch (json::parse_error& e) {
return;
}
First I receive a compiler warning saying discarding return value with a function declared with 'nodiscard' attribute and second I wan to be able to parse the message without wrapping the entire rest of my function in the exception handler. For instance I can just parse it twice like so.
try {
json::parse(message);
} catch (json::parse_error& e) {
return;
}
auto packet = json::parse(message);
Once to check if there's an error and the second to store the value in packet. Then I can use the packet structure, but that isn't very efficient because I'm parsing the message twice. I also can't store the return value in an auto type outside the block scope and assign it inside the block because auto wouldn't work that way. Essentially what I'm asking is, what does json::parse return so I can declare a variable for it outside the try catch and assign it inside the try catch then check if the assigned variable is valid.
I was reading through your examples I noticed your parse error example
First I receive a compiler warning saying discarding return value with a function declared with 'nodiscard' attribute and second I wan to be able to parse the message without wrapping the entire rest of my function in the exception handler. For instance I can just parse it twice like so.
Once to check if there's an error and the second to store the value in packet. Then I can use the packet structure, but that isn't very efficient because I'm parsing the message twice. I also can't store the return value in an auto type outside the block scope and assign it inside the block because auto wouldn't work that way. Essentially what I'm asking is, what does json::parse return so I can declare a variable for it outside the try catch and assign it inside the try catch then check if the assigned variable is valid.