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 calls abort function #769

Closed
tomasMizera opened this issue Oct 6, 2017 · 2 comments
Closed

Program calls abort function #769

tomasMizera opened this issue Oct 6, 2017 · 2 comments

Comments

@tomasMizera
Copy link

tomasMizera commented Oct 6, 2017

Hi, I am facing a problem while loading a .json file. I do it this way:

#include "json.hpp"
// for convenience
using json = nlohmann::json;

int main() {
	std::ifstream pah("eth_frame.json");
	json jFile;
	jFile << pah;
	cout << jFile["pi"];
....

line jFile << pah crashes and program ends with error, saying that it called abort() function.

When I try to debug, this problem occurs:
Unhandled exception at 0x753DB832 in JSONcpp.exe: Microsoft C++ exception: nlohmann::detail::parse_error at memory location 0x0133DE74.

In file json.hpp.
What am I doing wrong? Thanks in advance for your help! :)
btw, I use VS2017
error:
http://prntscr.com/gtzmwp

@tomasMizera
Copy link
Author

All right, I managed to fix this error. Problem was with input file, you better surround parsing with try/catch block, just like this:

std::fstream f_json("eth_frame.json");
json jFile;
try {
  jFile = json::parse(f_json);
}
catch (json::parse_error &e)
{
  std::cerr << e.what() << std::endl;
}

This post helped a lot! Thank you 👍 #582

@nlohmann
Copy link
Owner

nlohmann commented Oct 7, 2017

Thanks for reporting back!

@nlohmann nlohmann closed this as completed Oct 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants