diff --git a/jbmc/src/java_bytecode/java_bytecode_language.cpp b/jbmc/src/java_bytecode/java_bytecode_language.cpp index 65a4c8aac09..92ed7db4747 100644 --- a/jbmc/src/java_bytecode/java_bytecode_language.cpp +++ b/jbmc/src/java_bytecode/java_bytecode_language.cpp @@ -318,7 +318,7 @@ void java_bytecode_languaget::initialize_class_loader() static void throwMainClassLoadingError(const std::string &main_class) { - throw invalid_source_file_exceptiont( + throw system_exceptiont( "Error: Could not find or load main class " + main_class); } @@ -392,8 +392,7 @@ bool java_bytecode_languaget::parse( std::ifstream jar_file(path); if(!jar_file.good()) { - throw invalid_source_file_exceptiont( - "Error: Unable to access jarfile " + path); + throw system_exceptiont("Error: Unable to access jarfile " + path); } // build an object to potentially limit which classes are loaded diff --git a/jbmc/src/java_bytecode/lazy_goto_model.cpp b/jbmc/src/java_bytecode/lazy_goto_model.cpp index 1f3a4fc25a3..a0e9585c431 100644 --- a/jbmc/src/java_bytecode/lazy_goto_model.cpp +++ b/jbmc/src/java_bytecode/lazy_goto_model.cpp @@ -152,14 +152,14 @@ void lazy_goto_modelt::initialize( if(dynamic_cast(language).parse()) { - throw invalid_source_file_exceptiont("PARSING ERROR"); + throw invalid_input_exceptiont("PARSING ERROR"); } msg.status() << "Converting" << messaget::eom; if(language_files.typecheck(symbol_table)) { - throw invalid_source_file_exceptiont("CONVERSION ERROR"); + throw invalid_input_exceptiont("CONVERSION ERROR"); } } else diff --git a/src/crangler/ctokenit.cpp b/src/crangler/ctokenit.cpp index 1067dcfdf62..a9f727d6d5f 100644 --- a/src/crangler/ctokenit.cpp +++ b/src/crangler/ctokenit.cpp @@ -46,7 +46,7 @@ ctokenitt match_bracket(ctokenitt t, char open, char close) while(true) { if(!t) - throw invalid_source_file_exceptiont("expected " + std::string(1, close)); + throw invalid_input_exceptiont("expected " + std::string(1, close)); const auto &token = *(t++); diff --git a/src/crangler/mini_c_parser.cpp b/src/crangler/mini_c_parser.cpp index b7f4b5ac76c..0cb72bc7855 100644 --- a/src/crangler/mini_c_parser.cpp +++ b/src/crangler/mini_c_parser.cpp @@ -143,7 +143,7 @@ void mini_c_parsert::parse_brackets(char open, char close, tokenst &dest) while(true) { if(eof()) - throw invalid_source_file_exceptiont("expected " + std::string(1, close)); + throw invalid_input_exceptiont("expected " + std::string(1, close)); auto &token = consume_token(); dest.push_back(token); @@ -297,7 +297,7 @@ mini_c_parsert::tokenst mini_c_parsert::parse_initializer() while(true) { if(eof()) - throw invalid_source_file_exceptiont("expected an initializer"); + throw invalid_input_exceptiont("expected an initializer"); auto &token = consume_token(); result.push_back(token); if(token == ';') @@ -317,7 +317,7 @@ mini_c_parsert::tokenst mini_c_parsert::parse_initializer() while(true) { if(eof()) - throw invalid_source_file_exceptiont("eof in function body"); + throw invalid_input_exceptiont("eof in function body"); auto &token = consume_token(); result.push_back(token); if(token == '{') diff --git a/src/memory-analyzer/analyze_symbol.cpp b/src/memory-analyzer/analyze_symbol.cpp index eb84cc95ca3..565285ebfe2 100644 --- a/src/memory-analyzer/analyze_symbol.cpp +++ b/src/memory-analyzer/analyze_symbol.cpp @@ -350,7 +350,7 @@ exprt gdb_value_extractort::get_pointer_to_function_value( const auto function_symbol = symbol_table.lookup(function_name); if(function_symbol == nullptr) { - throw invalid_source_file_exceptiont{ + throw invalid_input_exceptiont{ "input source code does not contain function: " + function_name}; } CHECK_RETURN(function_symbol->type.id() == ID_code); diff --git a/src/symtab2gb/symtab2gb_parse_options.cpp b/src/symtab2gb/symtab2gb_parse_options.cpp index f1a6204a419..afcea1cfcbd 100644 --- a/src/symtab2gb/symtab2gb_parse_options.cpp +++ b/src/symtab2gb/symtab2gb_parse_options.cpp @@ -90,8 +90,8 @@ static void run_symtab2gb( if(failed(linking(linked_symbol_table, symtab, message_handler))) { - throw invalid_source_file_exceptiont{"failed to link `" + - symtab_filename + "'"}; + throw invalid_input_exceptiont{ + "failed to link `" + symtab_filename + "'"}; } } diff --git a/src/util/exception_utils.cpp b/src/util/exception_utils.cpp index 624f9d0f167..d1c6e4214bf 100644 --- a/src/util/exception_utils.cpp +++ b/src/util/exception_utils.cpp @@ -80,6 +80,11 @@ analysis_exceptiont::analysis_exceptiont(std::string reason) { } +invalid_input_exceptiont::invalid_input_exceptiont(std::string reason) + : cprover_exception_baset(std::move(reason)) +{ +} + invalid_source_file_exceptiont::invalid_source_file_exceptiont( std::string reason) : cprover_exception_baset(std::move(reason)) diff --git a/src/util/exception_utils.h b/src/util/exception_utils.h index f10e2b0689a..217c50bad23 100644 --- a/src/util/exception_utils.h +++ b/src/util/exception_utils.h @@ -156,6 +156,15 @@ class analysis_exceptiont : public cprover_exception_baset explicit analysis_exceptiont(std::string reason); }; +/// Thrown when user-provided input cannot be processed. Use +/// \ref invalid_source_file_exceptiont when the precise location of erroneous +/// input is known. +class invalid_input_exceptiont : public cprover_exception_baset +{ +public: + explicit invalid_input_exceptiont(std::string reason); +}; + /// Thrown when we can't handle something in an input source file. /// For example, if we get C source code that is not syntactically valid /// or that has type errors. diff --git a/unit/testing-utils/get_goto_model_from_c.cpp b/unit/testing-utils/get_goto_model_from_c.cpp index 18a8b927fd4..f6e9c2cd456 100644 --- a/unit/testing-utils/get_goto_model_from_c.cpp +++ b/unit/testing-utils/get_goto_model_from_c.cpp @@ -58,7 +58,7 @@ goto_modelt get_goto_model_from_c(std::istream &in) const bool error = language.parse(in, ""); if(error) - throw invalid_source_file_exceptiont("parsing failed"); + throw invalid_input_exceptiont("parsing failed"); } language_file.get_modules(); @@ -69,7 +69,7 @@ goto_modelt get_goto_model_from_c(std::istream &in) const bool error = language_files.typecheck(goto_model.symbol_table); if(error) - throw invalid_source_file_exceptiont("typechecking failed"); + throw invalid_input_exceptiont("typechecking failed"); } { @@ -77,8 +77,7 @@ goto_modelt get_goto_model_from_c(std::istream &in) language_files.generate_support_functions(goto_model.symbol_table); if(error) - throw invalid_source_file_exceptiont( - "support function generation failed"); + throw invalid_input_exceptiont("support function generation failed"); } goto_convert(