Skip to content

Commit a1c0def

Browse files
author
martin
committed
Remove the patchy exception handling in Java tools and use default
This is a copy of an earlier patch to the CBMC tools which replaced patchy and inconsistent exception handling in each tool with the comprehensive set of catch handlers in parse_options_baset.
1 parent 1e0bbc6 commit a1c0def

File tree

4 files changed

+8
-213
lines changed

4 files changed

+8
-213
lines changed

jbmc/src/janalyzer/janalyzer_parse_options.cpp

Lines changed: 5 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -355,29 +355,8 @@ int janalyzer_parse_optionst::doit()
355355

356356
register_languages();
357357

358-
try
359-
{
360-
goto_model =
361-
initialize_goto_model(cmdline.args, get_message_handler(), options);
362-
}
363-
364-
catch(const char *e)
365-
{
366-
error() << e << eom;
367-
return CPROVER_EXIT_EXCEPTION;
368-
}
369-
370-
catch(const std::string &e)
371-
{
372-
error() << e << eom;
373-
return CPROVER_EXIT_EXCEPTION;
374-
}
375-
376-
catch(int e)
377-
{
378-
error() << "Numeric exception: " << e << eom;
379-
return CPROVER_EXIT_EXCEPTION;
380-
}
358+
goto_model =
359+
initialize_goto_model(cmdline.args, get_message_handler(), options);
381360

382361
if(process_goto_program(options))
383362
return CPROVER_EXIT_INTERNAL_ERROR;
@@ -402,34 +381,7 @@ int janalyzer_parse_optionst::doit()
402381
return CPROVER_EXIT_SUCCESS;
403382
}
404383

405-
try
406-
{
407-
return perform_analysis(options);
408-
}
409-
410-
catch(const char *e)
411-
{
412-
error() << e << eom;
413-
return CPROVER_EXIT_EXCEPTION;
414-
}
415-
416-
catch(const std::string &e)
417-
{
418-
error() << e << eom;
419-
return CPROVER_EXIT_EXCEPTION;
420-
}
421-
422-
catch(int e)
423-
{
424-
error() << "Numeric exception: " << e << eom;
425-
return CPROVER_EXIT_EXCEPTION;
426-
}
427-
428-
catch(const std::bad_alloc &)
429-
{
430-
error() << "Out of memory" << eom;
431-
return CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY;
432-
}
384+
return perform_analysis(options);
433385
}
434386

435387
/// Depending on the command line mode, run one of the analysis tasks
@@ -554,8 +506,8 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
554506
return CPROVER_EXIT_SUCCESS;
555507
}
556508

557-
if(set_properties())
558-
return CPROVER_EXIT_SET_PROPERTIES_FAILED;
509+
if(cmdline.isset("property"))
510+
::set_properties(goto_model, cmdline.get_values("property"));
559511

560512
if(options.get_bool_option("general-analysis"))
561513
{
@@ -637,34 +589,6 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
637589
return CPROVER_EXIT_USAGE_ERROR;
638590
}
639591

640-
bool janalyzer_parse_optionst::set_properties()
641-
{
642-
try
643-
{
644-
if(cmdline.isset("property"))
645-
::set_properties(goto_model, cmdline.get_values("property"));
646-
}
647-
648-
catch(const char *e)
649-
{
650-
error() << e << eom;
651-
return true;
652-
}
653-
654-
catch(const std::string &e)
655-
{
656-
error() << e << eom;
657-
return true;
658-
}
659-
660-
catch(int)
661-
{
662-
return true;
663-
}
664-
665-
return false;
666-
}
667-
668592
bool janalyzer_parse_optionst::process_goto_program(const optionst &options)
669593
{
670594
try

jbmc/src/janalyzer/janalyzer_parse_options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ class janalyzer_parse_optionst : public parse_options_baset, public messaget
167167
virtual void get_command_line_options(optionst &options);
168168

169169
virtual bool process_goto_program(const optionst &options);
170-
bool set_properties();
171170

172171
virtual int perform_analysis(const optionst &options);
173172

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 3 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -425,22 +425,7 @@ int jbmc_parse_optionst::doit()
425425
//
426426

427427
optionst options;
428-
try
429-
{
430-
get_command_line_options(options);
431-
}
432-
433-
catch(const char *error_msg)
434-
{
435-
error() << error_msg << eom;
436-
return 6; // should contemplate EX_SOFTWARE from sysexits.h
437-
}
438-
439-
catch(const std::string &error_msg)
440-
{
441-
error() << error_msg << eom;
442-
return 6; // should contemplate EX_SOFTWARE from sysexits.h
443-
}
428+
get_command_line_options(options);
444429

445430
//
446431
// Print a banner
@@ -636,28 +621,8 @@ int jbmc_parse_optionst::doit()
636621

637622
bool jbmc_parse_optionst::set_properties(goto_modelt &goto_model)
638623
{
639-
try
640-
{
641-
if(cmdline.isset("property"))
642-
::set_properties(goto_model, cmdline.get_values("property"));
643-
}
644-
645-
catch(const char *e)
646-
{
647-
error() << e << eom;
648-
return true;
649-
}
650-
651-
catch(const std::string &e)
652-
{
653-
error() << e << eom;
654-
return true;
655-
}
656-
657-
catch(int)
658-
{
659-
return true;
660-
}
624+
if(cmdline.isset("property"))
625+
::set_properties(goto_model, cmdline.get_values("property"));
661626

662627
return false;
663628
}
@@ -672,7 +637,6 @@ int jbmc_parse_optionst::get_goto_program(
672637
return 6;
673638
}
674639

675-
try
676640
{
677641
lazy_goto_modelt lazy_goto_model=lazy_goto_modelt::from_handler_object(
678642
*this, options, get_message_handler());
@@ -738,29 +702,6 @@ int jbmc_parse_optionst::get_goto_program(
738702
status() << config.object_bits_info() << eom;
739703
}
740704

741-
catch(const char *e)
742-
{
743-
error() << e << eom;
744-
return 6;
745-
}
746-
747-
catch(const std::string &e)
748-
{
749-
error() << e << eom;
750-
return 6;
751-
}
752-
753-
catch(int)
754-
{
755-
return 6;
756-
}
757-
758-
catch(const std::bad_alloc &)
759-
{
760-
error() << "Out of memory" << eom;
761-
return 6;
762-
}
763-
764705
return -1; // no error, continue
765706
}
766707

@@ -776,7 +717,6 @@ void jbmc_parse_optionst::process_goto_function(
776717
bool using_symex_driven_loading =
777718
options.get_bool_option("symex-driven-lazy-loading");
778719

779-
try
780720
{
781721
// Removal of RTTI inspection:
782722
remove_instanceof(
@@ -861,24 +801,6 @@ void jbmc_parse_optionst::process_goto_function(
861801
// update the function member in each instruction
862802
function.update_instructions_function();
863803
}
864-
865-
catch(const char *e)
866-
{
867-
error() << e << eom;
868-
throw;
869-
}
870-
871-
catch(const std::string &e)
872-
{
873-
error() << e << eom;
874-
throw;
875-
}
876-
877-
catch(const std::bad_alloc &)
878-
{
879-
error() << "Out of memory" << eom;
880-
throw;
881-
}
882804
}
883805

884806
bool jbmc_parse_optionst::show_loaded_functions(
@@ -933,7 +855,6 @@ bool jbmc_parse_optionst::process_goto_functions(
933855
goto_modelt &goto_model,
934856
const optionst &options)
935857
{
936-
try
937858
{
938859
status() << "Running GOTO functions transformation passes" << eom;
939860

@@ -1021,29 +942,6 @@ bool jbmc_parse_optionst::process_goto_functions(
1021942
remove_skip(goto_model);
1022943
}
1023944

1024-
catch(const char *e)
1025-
{
1026-
error() << e << eom;
1027-
return true;
1028-
}
1029-
1030-
catch(const std::string &e)
1031-
{
1032-
error() << e << eom;
1033-
return true;
1034-
}
1035-
1036-
catch(int)
1037-
{
1038-
return true;
1039-
}
1040-
1041-
catch(const std::bad_alloc &)
1042-
{
1043-
error() << "Out of memory" << eom;
1044-
return true;
1045-
}
1046-
1047945
return false;
1048946
}
1049947

jbmc/src/jdiff/jdiff_parse_options.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ bool jdiff_parse_optionst::process_goto_program(
342342
const optionst &options,
343343
goto_modelt &goto_model)
344344
{
345-
try
346345
{
347346
// remove function pointers
348347
status() << "Removing function pointers and virtual functions" << eom;
@@ -407,31 +406,6 @@ bool jdiff_parse_optionst::process_goto_program(
407406
goto_model.goto_functions.update();
408407
}
409408

410-
catch(const char *e)
411-
{
412-
error() << e << eom;
413-
return true;
414-
}
415-
416-
catch(const std::string &e)
417-
{
418-
error() << e << eom;
419-
return true;
420-
}
421-
422-
catch(int e)
423-
{
424-
error() << "Numeric exception: " << e << eom;
425-
return true;
426-
}
427-
428-
catch(const std::bad_alloc &)
429-
{
430-
error() << "Out of memory" << eom;
431-
exit(CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY);
432-
return true;
433-
}
434-
435409
return false;
436410
}
437411

0 commit comments

Comments
 (0)