exceptions related fixes
This commit is contained in:
parent
b7cbc64277
commit
7d939a49dd
18
ml.cpp
18
ml.cpp
|
|
@ -1239,7 +1239,6 @@ MlValue read_url(std::vector<MlValue> args, MlEnvironment &env) {
|
|||
MlValue parse_json(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
eval_args(args, env);
|
||||
|
||||
// TODO add support for more params specifying options
|
||||
if (args.size() != 1)
|
||||
throw MlError(MlValue("parse-json", parse_json), env, args.size() > 1 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||
|
||||
|
|
@ -1247,10 +1246,9 @@ MlValue parse_json(std::vector<MlValue> args, MlEnvironment &env) {
|
|||
std::string err;
|
||||
auto json = json11::Json::parse(str, err);
|
||||
|
||||
if (!err.empty()) {
|
||||
// TODO handle error
|
||||
if (!err.empty())
|
||||
return MlValue::string("ERROR json parsing: " + err);
|
||||
}
|
||||
|
||||
|
||||
return json.ivalualize();
|
||||
}
|
||||
|
|
@ -1973,9 +1971,10 @@ MlValue thread_create(std::vector<MlValue> args, MlEnvironment &env) {
|
|||
MlValue acc = arg.eval(env);
|
||||
} catch (const MlError &e) {
|
||||
std::cerr << "thread_create exception: " << e.description() << std::endl;
|
||||
throw;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "thread_create exception: " << e.what() << std::endl;
|
||||
throw e;
|
||||
throw;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -2058,10 +2057,12 @@ MlValue try_block(std::vector<MlValue> args, MlEnvironment &env) {
|
|||
}
|
||||
|
||||
MlValue throw_exception(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
eval_args(args, env);
|
||||
|
||||
if (args.size() != 1)
|
||||
throw MlError(MlValue("throw", throw_exception), env, args.size() > 1 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||
|
||||
throw std::runtime_error(args[0].as_string());
|
||||
throw std::runtime_error(args[0].cast_to_string().as_string());
|
||||
}
|
||||
|
||||
MlValue usql(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
|
|
@ -2356,10 +2357,10 @@ int main(int argc, char *argv[]) {
|
|||
run(read_file_contents(file), env);
|
||||
// sheebang
|
||||
} else if (cmdOptionExists(argv, argv + argc, "-run")) {
|
||||
for (auto & file : getCmdOption(argv, argc, "-run")) { // TODO check only one file is specified ??
|
||||
for (auto & file : getCmdOption(argv, argc, "-run")) {
|
||||
std::string file_content = read_file_contents(file);
|
||||
if (file_content.find("#!") == 0) // shebang ?
|
||||
file_content.erase(0, file_content.find('\n') + 1); // TODO mac osx newline??
|
||||
file_content.erase(0, file_content.find('\n') + 1);
|
||||
|
||||
run(file_content, env);
|
||||
}
|
||||
|
|
@ -2376,7 +2377,6 @@ int main(int argc, char *argv[]) {
|
|||
std::cerr << e.description() << std::endl;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << MlPerfMon::instance().callstack() << e.what() << std::endl;
|
||||
MlPerfMon::instance().clear_callstack();
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue