# HG changeset patch # User John W. Eaton # Date 1380055280 14400 # Node ID 9849075a5da6edbfe28a432cbf84e6b8bedc3835 # Parent bddb9688e41c1daca054d3219e8ba20d494f99c8 allow objects to load if constructor fails but loadobj method succeeds * ov-class.cc (octave_class::reconstruct_exemplar): Don't throw error if constructor execution fails. (octave_class::load_ascii, octave_class::load_binary, octave_class::load_hdf5): Attempt to handle exemplar and loadobj method consistently. diff --git a/libinterp/octave-value/ov-class.cc b/libinterp/octave-value/ov-class.cc --- a/libinterp/octave-value/ov-class.cc +++ b/libinterp/octave-value/ov-class.cc @@ -1239,13 +1239,19 @@ if (have_ctor) { + unwind_protect frame; + + // Simulate try/catch. + + interpreter_try (frame); + octave_value_list result = ctor.do_multi_index_op (1, octave_value_list ()); - if (result.length () == 1) + if (! error_state && result.length () == 1) retval = true; - else - warning ("call to constructor for class %s failed", c_name.c_str ()); + + error_state = false; } else warning ("no constructor for class %s", c_name.c_str ()); @@ -1401,19 +1407,17 @@ if (! reconstruct_parents ()) warning ("load: unable to reconstruct object inheritance"); - else + + if (load_path::find_method (classname, "loadobj") + != std::string ()) { - if (load_path::find_method (classname, "loadobj") - != std::string ()) - { - octave_value in = new octave_class (*this); - octave_value_list tmp = feval ("loadobj", in, 1); + octave_value in = new octave_class (*this); + octave_value_list tmp = feval ("loadobj", in, 1); - if (! error_state) - map = tmp(0).map_value (); - else - success = false; - } + if (! error_state) + map = tmp(0).map_value (); + else + success = false; } } else @@ -1548,18 +1552,16 @@ if (! reconstruct_parents ()) warning ("load: unable to reconstruct object inheritance"); - else + + if (load_path::find_method (c_name, "loadobj") != std::string ()) { - if (load_path::find_method (c_name, "loadobj") != std::string ()) - { - octave_value in = new octave_class (*this); - octave_value_list tmp = feval ("loadobj", in, 1); + octave_value in = new octave_class (*this); + octave_value_list tmp = feval ("loadobj", in, 1); - if (! error_state) - map = tmp(0).map_value (); - else - success = false; - } + if (! error_state) + map = tmp(0).map_value (); + else + success = false; } } else @@ -1788,23 +1790,19 @@ if (!reconstruct_parents ()) warning ("load: unable to reconstruct object inheritance"); - else - { - if (load_path::find_method (c_name, "loadobj") != std::string ()) - { - octave_value in = new octave_class (*this); - octave_value_list tmp = feval ("loadobj", in, 1); - if (! error_state) - { - map = tmp(0).map_value (); - retval = true; - } - else - retval = false; + if (load_path::find_method (c_name, "loadobj") != std::string ()) + { + octave_value in = new octave_class (*this); + octave_value_list tmp = feval ("loadobj", in, 1); + + if (! error_state) + { + map = tmp(0).map_value (); + retval = true; } else - retval = true; + retval = false; } }