Skip to content

try/catch block does not catch parsing error #2579

Description

@bfamzz

What is the issue you have?

try/catch block does not catch parsing error

Error message is:
[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'A'

Please describe the steps to reproduce the issue.

  1. Sample code is provided below.

Can you provide a small but working code example?

#include<iostream>
#include <nlohmann/json.hpp>

int main()
{
    try
    {
        nlohmann::json jsonObject = nlohmann::json::parse("Alright");
        std::cout << "Parse completed!\n";
    }
    catch(const std::exception& e)
    {
        std::cerr << e.what() << '\n';
        return -1;
    }
    return 0;
}

What is the expected behavior?

Error should be caught in the try/catch block and program should continue execution.

And what is the actual behavior instead?

Program crashes while in the try block. Parsing error is not caught.

Which compiler and operating system are you using?

  • Compiler: GCC 9.3.0 && GCC 10.1.0
  • Operating system: Linux - Ubuntu 20.04

Which version of the library did you use?

  • [x] latest release version 3.9.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: invalidthe issue is not related to the library

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions