changeset 20741:a5ab31b52ae8

eliminate more uses of error_state * __qp__.cc, besselj.cc, data.cc, file-io.cc, input.cc, load-save.cc, ls-oct-text.cc, oct-map.cc, oct-stream.cc, syscalls.cc, toplev.cc, ov-base.cc, ov-cell.cc, ov-fcn-handle.cc: Eliminate more uses of error_state. * ov.h, ov.cc (octave_value::xfunction_value, octave_value::xuser_function_value, octave_value::xuser_script_value, octave_value::xuser_code_value, octave_value::xfcn_handle_value, octave_value::xfcn_inline_value, octave_value::xlist_value): New value extraction functions.
author John W. Eaton <jwe@octave.org>
date Mon, 23 Nov 2015 20:50:07 -0500
parents bba1a5fd4d8c
children 5e2da9a66510
files libinterp/corefcn/__qp__.cc libinterp/corefcn/besselj.cc libinterp/corefcn/data.cc libinterp/corefcn/file-io.cc libinterp/corefcn/input.cc libinterp/corefcn/load-save.cc libinterp/corefcn/ls-oct-text.cc libinterp/corefcn/oct-map.cc libinterp/corefcn/oct-stream.cc libinterp/corefcn/syscalls.cc libinterp/corefcn/toplev.cc libinterp/octave-value/ov-base.cc libinterp/octave-value/ov-cell.cc libinterp/octave-value/ov-fcn-handle.cc libinterp/octave-value/ov.cc libinterp/octave-value/ov.h
diffstat 16 files changed, 508 insertions(+), 525 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/__qp__.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/corefcn/__qp__.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -136,12 +136,15 @@
 
   // Computing the ???
 
-  EIG eigH (H);
+  EIG eigH;
 
-  if (error_state)
+  try
+    {
+      eigH = EIG (H);
+    }
+  catch (const octave_execution_exception&)
     {
       error ("qp: failed to compute eigenvalues of H");
-      return -1;
     }
 
   ColumnVector eigenvalH = real (eigH.eigenvalues ());
@@ -281,12 +284,15 @@
 
               // Searching for the most negative curvature.
 
-              EIG eigrH (rH);
+              EIG eigrH;
 
-              if (error_state)
+              try
+                {
+                  eigrH = EIG (rH);
+                }
+              catch (const octave_execution_exception&)
                 {
                   error ("qp: failed to compute eigenvalues of rH");
-                  return -1;
                 }
 
               ColumnVector eigenvalrH = real (eigrH.eigenvalues ());
--- a/libinterp/corefcn/besselj.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/corefcn/besselj.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -29,7 +29,6 @@
 
 #include "defun.h"
 #include "error.h"
-#include "gripes.h"
 #include "oct-obj.h"
 #include "utils.h"
 
@@ -78,12 +77,6 @@
     } \
   while (0)
 
-static void
-gripe_bessel_arg (const char *fn, const char *arg)
-{
-  error ("%s: %s argument must be a scalar or matrix", fn, arg);
-}
-
 octave_value_list
 do_bessel (enum bessel_type type, const char *fn,
            const octave_value_list& args, int nargout)
--- a/libinterp/corefcn/data.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/corefcn/data.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -1804,10 +1804,19 @@
 
   if (fcn.is_defined ())
     {
-      octave_value_list result
-        = fcn.do_multi_index_op (1, octave_value_list (1, ov));
-
-      if (! error_state && result.length () > 0)
+      octave_value_list result;
+
+      try
+        {
+          result = fcn.do_multi_index_op (1, octave_value_list (1, ov));
+        }
+      catch (const octave_execution_exception&)
+        {
+          error ("conversion from %s to %s failed", dtype.c_str (),
+                 cname.c_str ());
+        }
+
+      if (result.length () > 0)
         retval = result(0);
       else
         error ("conversion from %s to %s failed", dtype.c_str (),
@@ -1822,10 +1831,19 @@
 
       if (fcn.is_defined ())
         {
-          octave_value_list result
-            = fcn.do_multi_index_op (1, octave_value_list (1, ov));
-
-          if (! error_state && result.length () > 0)
+          octave_value_list result;
+
+          try
+            {
+              result = fcn.do_multi_index_op (1, octave_value_list (1, ov));
+            }
+          catch (const octave_execution_exception&)
+            {
+              error ("%s constructor failed for %s argument", dtype.c_str (),
+                     cname.c_str ());
+            }
+
+          if (result.length () > 0)
             retval = result(0);
           else
             error ("%s constructor failed for %s argument", dtype.c_str (),
@@ -1853,16 +1871,22 @@
     {
       // Have method for dominant type.  Call it and let it handle conversions.
 
-      octave_value_list tmp2 = fcn.do_multi_index_op (1, ovl);
+      octave_value_list tmp2;
+
+      try
+        {
+          tmp2 = fcn.do_multi_index_op (1, ovl);
+        }
+      catch (const octave_execution_exception&)
+        {
+          error ("%s/%s method failed", dtype.c_str (), cattype.c_str ());
+        }
 
       if (tmp2.length () > 0)
         retval = tmp2(0);
       else
-        {
-          error ("%s/%s method did not return a value",
-                 dtype.c_str (), cattype.c_str ());
-          goto done;
-        }
+        error ("%s/%s method did not return a value", dtype.c_str (),
+               cattype.c_str ());
     }
   else
     {
@@ -1895,7 +1919,6 @@
       retval = octave_value (new octave_class (m, cname, parents));
     }
 
-done:
   return retval;
 }
 
--- a/libinterp/corefcn/file-io.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/corefcn/file-io.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -1317,8 +1317,6 @@
           const octave_value& prec_arg, const octave_value& skip_arg,
           const octave_value& arch_arg, octave_idx_type& count)
 {
-  octave_value retval;
-
   count = -1;
 
   Array<double> size = size_arg.xvector_value ("fread: invalid SIZE specified");
@@ -1329,30 +1327,34 @@
   oct_data_conv::data_type input_type;
   oct_data_conv::data_type output_type;
 
-  oct_data_conv::string_to_data_type (prec, block_size,
-                                      input_type, output_type);
-
-  if (! error_state)
+  try
     {
-      int skip = skip_arg.int_value (true);
+      oct_data_conv::string_to_data_type (prec, block_size,
+                                          input_type, output_type);
+    }
+  catch (const octave_execution_exception&)
+    {
+      error ("fread: invalid PRECISION specified");
+    }
 
-      if (! error_state)
-        {
-          std::string arch = arch_arg.xstring_value ("fread: ARCH architecture type must be a string");
+  int skip;
 
-          oct_mach_info::float_format flt_fmt
-            = oct_mach_info::string_to_float_format (arch);
+  try
+    {
+      skip = skip_arg.int_value (true);
+    }
+  catch (const octave_execution_exception&)
+    {
+      error ("fread: SKIP must be an integer");
+    }
 
-          retval = os.read (size, block_size, input_type,
-                            output_type, skip, flt_fmt, count);
-        }
-      else
-        error ("fread: SKIP must be an integer");
-    }
-  else
-    error ("fread: invalid PRECISION specified");
+  std::string arch = arch_arg.xstring_value ("fread: ARCH architecture type must be a string");
 
-  return retval;
+  oct_mach_info::float_format flt_fmt
+    = oct_mach_info::string_to_float_format (arch);
+
+  return os.read (size, block_size, input_type, output_type, skip,
+                  flt_fmt, count);
 }
 
 DEFUN (fread, args, ,
@@ -1579,36 +1581,37 @@
            const octave_value& prec_arg, const octave_value& skip_arg,
            const octave_value& arch_arg)
 {
-  int retval = -1;
-
   std::string prec = prec_arg.xstring_value ("fwrite: PRECISION must be a string");
 
   int block_size = 1;
   oct_data_conv::data_type output_type;
 
-  oct_data_conv::string_to_data_type (prec, block_size, output_type);
-
-  if (! error_state)
+  try
     {
-      int skip = skip_arg.int_value (true);
+      oct_data_conv::string_to_data_type (prec, block_size, output_type);
+    }
+  catch (const octave_execution_exception&)
+    {
+      error ("fwrite: invalid PRECISION specified");
+    }
 
-      if (! error_state)
-        {
-          std::string arch = arch_arg.xstring_value ("fwrite: ARCH architecture type must be a string");
+  int skip;
 
-          oct_mach_info::float_format flt_fmt
-            = oct_mach_info::string_to_float_format (arch);
+  try
+    {
+      skip = skip_arg.int_value (true);
+    }
+  catch (const octave_execution_exception&)
+    {
+      error ("fwrite: SKIP must be an integer");
+    }
 
-          retval = os.write (data, block_size, output_type,
-                             skip, flt_fmt);
-        }
-      else
-        error ("fwrite: SKIP must be an integer");
-    }
-  else
-    error ("fwrite: invalid PRECISION specified");
+  std::string arch = arch_arg.xstring_value ("fwrite: ARCH architecture type must be a string");
 
-  return retval;
+  oct_mach_info::float_format flt_fmt
+    = oct_mach_info::string_to_float_format (arch);
+
+  return os.write (data, block_size, output_type, skip, flt_fmt);
 }
 
 DEFUN (fwrite, args, ,
--- a/libinterp/corefcn/input.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/corefcn/input.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -1261,17 +1261,12 @@
 
       hook_function hook_fcn (args(0), user_data);
 
-      if (! error_state)
-        {
-          if (input_event_hook_functions.empty ())
-            command_editor::add_event_hook (internal_input_event_hook_fcn);
+      if (input_event_hook_functions.empty ())
+        command_editor::add_event_hook (internal_input_event_hook_fcn);
 
-          input_event_hook_functions.insert (hook_fcn.id (), hook_fcn);
+      input_event_hook_functions.insert (hook_fcn.id (), hook_fcn);
 
-          retval = hook_fcn.id ();
-        }
-      else
-        error ("add_input_event_hook: FCN must be a function handle or string");
+      retval = hook_fcn.id ();
     }
   else
     print_usage ();
--- a/libinterp/corefcn/load-save.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/corefcn/load-save.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -398,7 +398,7 @@
           break;
         }
 
-      if (error_state || stream.eof () || name.empty ())
+      if (stream.eof () || name.empty ())
         break;
       else
         {
--- a/libinterp/corefcn/ls-oct-text.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/corefcn/ls-oct-text.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -251,11 +251,8 @@
 
   if (! (name == ".nargin." || name == ".nargout."
          || name == CELL_ELT_TAG || valid_identifier (name)))
-    {
-      error ("load: bogus identifier '%s' found in file '%s'",
-             name.c_str (), filename.c_str ());
-      return std::string ();
-    }
+    error ("load: bogus identifier '%s' found in file '%s'",
+           name.c_str (), filename.c_str ());
 
   // Look for type keyword.
 
@@ -287,12 +284,6 @@
   else
     error ("load: failed to extract keyword specifying value type");
 
-  if (error_state)
-    {
-      error ("load: reading file %s", filename.c_str ());
-      return std::string ();
-    }
-
   return name;
 }
 
--- a/libinterp/corefcn/oct-map.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/corefcn/oct-map.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -639,20 +639,21 @@
 
   Array<octave_idx_type> perm (dim_vector (1, nf));
 
-  for (octave_idx_type i = 0; i < n; i++)
+  try
     {
-      if (i == idx)
-        continue;
+      for (octave_idx_type i = 0; i < n; i++)
+        {
+          if (i == idx)
+            continue;
 
-      permute_to_correct_order1 (map_list[idx], map_list[i], new_map_list[i],
-                                 perm);
-
-      if (error_state)
-        {
-          error ("cat: field names mismatch in concatenating structs");
-          break;
+          permute_to_correct_order1 (map_list[idx], map_list[i],
+                                     new_map_list[i], perm);
         }
     }
+  catch (const octave_execution_exception&)
+    {
+      error ("cat: field names mismatch in concatenating structs");
+    }
 }
 
 
@@ -994,14 +995,19 @@
   else
     {
       Array<octave_idx_type> perm;
-      octave_map rhs1 = rhs.orderfields (*this, perm);
-      if (! error_state)
+      octave_map rhs1;
+
+      try
         {
-          assert (rhs1.xkeys.is_same (xkeys));
-          assign (i, rhs1);
+          rhs1 = rhs.orderfields (*this, perm);
         }
-      else
-        error ("incompatible fields in struct assignment");
+      catch (const octave_execution_exception&)
+        {
+          error ("incompatible fields in struct assignment");
+        }
+
+      assert (rhs1.xkeys.is_same (xkeys));
+      assign (i, rhs1);
     }
 }
 
@@ -1037,14 +1043,19 @@
   else
     {
       Array<octave_idx_type> perm;
-      octave_map rhs1 = rhs.orderfields (*this, perm);
-      if (! error_state)
+      octave_map rhs1;
+
+      try
         {
-          assert (rhs1.xkeys.is_same (xkeys));
-          assign (i, j, rhs1);
+          rhs1 = rhs.orderfields (*this, perm);
         }
-      else
-        error ("incompatible fields in struct assignment");
+      catch (const octave_execution_exception&)
+        {
+          error ("incompatible fields in struct assignment");
+        }
+
+      assert (rhs1.xkeys.is_same (xkeys));
+      assign (i, j, rhs1);
     }
 }
 
@@ -1080,14 +1091,19 @@
   else
     {
       Array<octave_idx_type> perm;
-      octave_map rhs1 = rhs.orderfields (*this, perm);
-      if (! error_state)
+      octave_map rhs1;
+
+      try
         {
-          assert (rhs1.xkeys.is_same (xkeys));
-          assign (ia, rhs1);
+          rhs1 = rhs.orderfields (*this, perm);
         }
-      else
-        error ("incompatible fields in struct assignment");
+      catch (const octave_execution_exception&)
+        {
+          error ("incompatible fields in struct assignment");
+        }
+
+      assert (rhs1.xkeys.is_same (xkeys));
+      assign (ia, rhs1);
     }
 }
 
--- a/libinterp/corefcn/oct-stream.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/corefcn/oct-stream.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -65,24 +65,28 @@
 
   conv_err = 0;
 
-  double dval = tc.double_value ();
-
-  if (! error_state)
+  double dval;
+
+  try
+    {
+      dval = tc.double_value ();
+    }
+  catch (const octave_execution_exception&)
     {
-      if (! lo_ieee_isnan (dval))
-        {
-          int ival = NINT (dval);
-
-          if (ival == dval)
-            retval = ival;
-          else
-            conv_err = 3;
-        }
+      conv_err = 1;
+    }
+
+  if (! lo_ieee_isnan (dval))
+    {
+      int ival = NINT (dval);
+
+      if (ival == dval)
+        retval = ival;
       else
-        conv_err = 2;
+        conv_err = 3;
     }
   else
-    conv_err = 1;
+    conv_err = 2;
 
   return retval;
 }
@@ -2246,19 +2250,9 @@
         {
           curr_val = values (val_idx);
 
-          // Force string conversion here for compatibility.
-
-          if (! error_state)
-            {
-              elt_idx = 0;
-              n_elts = curr_val.numel ();
-              have_data = true;
-            }
-          else
-            {
-              curr_state = conversion_error;
-              break;
-            }
+          elt_idx = 0;
+          n_elts = curr_val.numel ();
+          have_data = true;
         }
 
       if (elt_idx < n_elts)
@@ -3369,165 +3363,167 @@
 
       count = 0;
 
-      get_size (size, nr, nc, one_elt_size_spec, "fread");
-
-      if (! error_state)
+      try
+        {
+          get_size (size, nr, nc, one_elt_size_spec, "fread");
+        }
+      catch (const octave_execution_exception&)
         {
-          octave_idx_type elts_to_read;
-
-          if (one_elt_size_spec)
-            {
-              // If NR == 0, Matlab returns [](0x0).
-
-              // If NR > 0, the result will be a column vector with the given
-              // number of rows.
-
-              // If NR < 0, then we have Inf and the result will be a column
-              // vector but we have to wait to see how big NR will be.
-
-              if (nr == 0)
-                nr = nc = 0;
-              else
-                nc = 1;
-            }
-          else
-            {
-              // Matlab returns [] even if there are two elements in the size
-              // specification and one is nonzero.
-
-              // If NC < 0 we have [NR, Inf] and we'll wait to decide how big NC
-              // should be.
-
-              if (nr == 0 || nc == 0)
-                nr = nc = 0;
-            }
-
-          // FIXME: Ensure that this does not overflow.
-          //        Maybe try comparing nr * nc computed in double with
-          //        std::numeric_limits<octave_idx_type>::max ();
-
-          elts_to_read = nr * nc;
-
-          bool read_to_eof = elts_to_read < 0;
-
-          octave_idx_type input_buf_elts = -1;
-
-          if (skip == 0)
-            {
-              if (read_to_eof)
-                input_buf_elts = 1024 * 1024;
-              else
-                input_buf_elts = elts_to_read;
-            }
+          invalid_operation ("fread", "reading");
+        }
+
+      octave_idx_type elts_to_read;
+
+      if (one_elt_size_spec)
+        {
+          // If NR == 0, Matlab returns [](0x0).
+
+          // If NR > 0, the result will be a column vector with the given
+          // number of rows.
+
+          // If NR < 0, then we have Inf and the result will be a column
+          // vector but we have to wait to see how big NR will be.
+
+          if (nr == 0)
+            nr = nc = 0;
           else
-            input_buf_elts = block_size;
-
-          octave_idx_type input_elt_size
-            = oct_data_conv::data_type_size (input_type);
-
-          octave_idx_type input_buf_size = input_buf_elts * input_elt_size;
-
-          assert (input_buf_size >= 0);
-
-          // Must also work and return correct type object
-          // for 0 elements to read.
-
-          std::istream *isp = input_stream ();
-
-          if (isp)
-            {
-              std::istream& is = *isp;
-
-              std::list <void *> input_buf_list;
-
-              while (is && ! is.eof ()
-                     && (read_to_eof || count < elts_to_read))
-                {
-                  if (! read_to_eof)
-                    {
-                      octave_idx_type remaining_elts = elts_to_read - count;
-
-                      if (remaining_elts < input_buf_elts)
-                        input_buf_size = remaining_elts * input_elt_size;
-                    }
-
-                  char *input_buf = new char [input_buf_size];
-
-                  is.read (input_buf, input_buf_size);
-
-                  size_t gcount = is.gcount ();
-
-                  char_count += gcount;
-
-                  octave_idx_type nel = gcount / input_elt_size;
-
-                  count += nel;
-
-                  input_buf_list.push_back (input_buf);
-
-                  if (is && skip != 0 && nel == block_size)
-                    {
-                      // Seek to skip.  If skip would move past EOF,
-                      // position at EOF.
-
-                      off_t orig_pos = tell ();
-
-                      seek (0, SEEK_END);
-
-                      off_t eof_pos = tell ();
-
-                      // Is it possible for this to fail to return us to
-                      // the original position?
-                      seek (orig_pos, SEEK_SET);
-
-                      off_t remaining = eof_pos - orig_pos;
-
-                      if (remaining < skip)
-                        seek (0, SEEK_END);
-                      else
-                        seek (skip, SEEK_CUR);
-
-                      if (! is)
-                        break;
-                    }
-                }
-
-              if (read_to_eof)
-                {
-                  if (nc < 0)
-                    {
-                      nc = count / nr;
-
-                      if (count % nr != 0)
-                        nc++;
-                    }
-                  else
-                    nr = count;
-                }
-              else if (count == 0)
-                {
-                  nr = 0;
-                  nc = 0;
-                }
-              else if (count != nr * nc)
-                {
-                  if (count % nr != 0)
-                    nc = count / nr + 1;
-                  else
-                    nc = count / nr;
-
-                  if (count < nr)
-                    nr = count;
-                }
-
-              retval = finalize_read (input_buf_list, input_buf_elts, count,
-                                      nr, nc, input_type, output_type, ffmt);
-            }
+            nc = 1;
+        }
+      else
+        {
+          // Matlab returns [] even if there are two elements in the size
+          // specification and one is nonzero.
+
+          // If NC < 0 we have [NR, Inf] and we'll wait to decide how big NC
+          // should be.
+
+          if (nr == 0 || nc == 0)
+            nr = nc = 0;
+        }
+
+      // FIXME: Ensure that this does not overflow.
+      //        Maybe try comparing nr * nc computed in double with
+      //        std::numeric_limits<octave_idx_type>::max ();
+
+      elts_to_read = nr * nc;
+
+      bool read_to_eof = elts_to_read < 0;
+
+      octave_idx_type input_buf_elts = -1;
+
+      if (skip == 0)
+        {
+          if (read_to_eof)
+            input_buf_elts = 1024 * 1024;
           else
-            error ("fread: invalid input stream");
+            input_buf_elts = elts_to_read;
         }
       else
-        invalid_operation ("fread", "reading");
+        input_buf_elts = block_size;
+
+      octave_idx_type input_elt_size
+                                        = oct_data_conv::data_type_size (input_type);
+
+      octave_idx_type input_buf_size = input_buf_elts * input_elt_size;
+
+      assert (input_buf_size >= 0);
+
+      // Must also work and return correct type object
+      // for 0 elements to read.
+
+      std::istream *isp = input_stream ();
+
+      if (isp)
+        {
+          std::istream& is = *isp;
+
+          std::list <void *> input_buf_list;
+
+          while (is && ! is.eof ()
+                 && (read_to_eof || count < elts_to_read))
+            {
+              if (! read_to_eof)
+                {
+                  octave_idx_type remaining_elts = elts_to_read - count;
+
+                  if (remaining_elts < input_buf_elts)
+                    input_buf_size = remaining_elts * input_elt_size;
+                }
+
+              char *input_buf = new char [input_buf_size];
+
+              is.read (input_buf, input_buf_size);
+
+              size_t gcount = is.gcount ();
+
+              char_count += gcount;
+
+              octave_idx_type nel = gcount / input_elt_size;
+
+              count += nel;
+
+              input_buf_list.push_back (input_buf);
+
+              if (is && skip != 0 && nel == block_size)
+                {
+                  // Seek to skip.  If skip would move past EOF,
+                  // position at EOF.
+
+                  off_t orig_pos = tell ();
+
+                  seek (0, SEEK_END);
+
+                  off_t eof_pos = tell ();
+
+                  // Is it possible for this to fail to return us to
+                  // the original position?
+                  seek (orig_pos, SEEK_SET);
+
+                  off_t remaining = eof_pos - orig_pos;
+
+                  if (remaining < skip)
+                    seek (0, SEEK_END);
+                  else
+                    seek (skip, SEEK_CUR);
+
+                  if (! is)
+                    break;
+                }
+            }
+
+          if (read_to_eof)
+            {
+              if (nc < 0)
+                {
+                  nc = count / nr;
+
+                  if (count % nr != 0)
+                    nc++;
+                }
+              else
+                nr = count;
+            }
+          else if (count == 0)
+            {
+              nr = 0;
+              nc = 0;
+            }
+          else if (count != nr * nc)
+            {
+              if (count % nr != 0)
+                nc = count / nr + 1;
+              else
+                nc = count / nr;
+
+              if (count < nr)
+                nr = count;
+            }
+
+          retval = finalize_read (input_buf_list, input_buf_elts, count,
+                                  nr, nc, input_type, output_type, ffmt);
+        }
+      else
+        error ("fread: invalid input stream");
     }
 
   return retval;
@@ -3542,22 +3538,19 @@
 
   if (stream_ok ())
     {
-      if (! error_state)
-        {
-          if (flt_fmt == oct_mach_info::flt_fmt_unknown)
-            flt_fmt = float_format ();
-
-          octave_idx_type status = data.write (*this, block_size, output_type,
-                                               skip, flt_fmt);
-
-          if (status < 0)
-            error ("fwrite: write error");
-          else
-            retval = status;
-        }
+      if (flt_fmt == oct_mach_info::flt_fmt_unknown)
+        flt_fmt = float_format ();
+
+      octave_idx_type status = data.write (*this, block_size, output_type,
+                                           skip, flt_fmt);
+
+      if (status < 0)
+        error ("fwrite: write error");
       else
-        invalid_operation ("fwrite", "writing");
+        retval = status;
     }
+  else
+    invalid_operation ("fwrite", "writing");
 
   return retval;
 }
--- a/libinterp/corefcn/syscalls.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/corefcn/syscalls.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -132,26 +132,21 @@
       octave_stream old_stream
         = octave_stream_list::lookup (args(0), "dup2");
 
-      if (! error_state)
-        {
-          octave_stream new_stream
-            = octave_stream_list::lookup (args(1), "dup2");
+      octave_stream new_stream
+        = octave_stream_list::lookup (args(1), "dup2");
 
-          int i_old = old_stream.file_number ();
-          int i_new = new_stream.file_number ();
+      int i_old = old_stream.file_number ();
+      int i_new = new_stream.file_number ();
 
-          if (i_old >= 0 && i_new >= 0)
-            {
-              std::string msg;
-
-              int status = octave_syscalls::dup2 (i_old, i_new, msg);
+      if (i_old >= 0 && i_new >= 0)
+        {
+          std::string msg;
 
-              retval(1) = msg;
-              retval(0) = status;
-            }
+          int status = octave_syscalls::dup2 (i_old, i_new, msg);
+
+          retval(1) = msg;
+          retval(0) = status;
         }
-      else
-        error ("dup2: invalid stream");
     }
   else
     print_usage ();
@@ -486,28 +481,23 @@
     {
       octave_stream strm = octave_stream_list::lookup (args(0), "fcntl");
 
-      if (! error_state)
-        {
-          int fid = strm.file_number ();
+      int fid = strm.file_number ();
 
-          int req = args(1).int_value (true);
-          int arg = args(2).int_value (true);
+      int req = args(1).int_value (true);
+      int arg = args(2).int_value (true);
 
-          // FIXME: Need better checking here?
-          if (fid < 0)
-            error ("fcntl: invalid file id");
-          else
-            {
-              std::string msg;
+      // FIXME: Need better checking here?
+      if (fid < 0)
+        error ("fcntl: invalid file id");
+      else
+        {
+          std::string msg;
 
-              int status = octave_fcntl (fid, req, arg, msg);
+          int status = octave_fcntl (fid, req, arg, msg);
 
-              retval(1) = msg;
-              retval(0) = status;
-            }
+          retval(1) = msg;
+          retval(0) = status;
         }
-      else
-        error ("fcntl: FID, REQUEST, and ARG must be integers");
     }
   else
     print_usage ();
--- a/libinterp/corefcn/toplev.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/corefcn/toplev.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -630,22 +630,10 @@
                         break;
                     }
 
-                  if (error_state)
-                    {
-                      if (! interactive)
-                        {
-                          // We should exit with a nonzero status.
-                          retval = 1;
-                          break;
-                        }
-                    }
+                  if (octave_completion_matches_called)
+                    octave_completion_matches_called = false;
                   else
-                    {
-                      if (octave_completion_matches_called)
-                        octave_completion_matches_called = false;
-                      else
-                        command_editor::increment_current_command_number ();
-                    }
+                    command_editor::increment_current_command_number ();
                 }
               else if (parser.lexer.end_of_input)
                 break;
@@ -672,7 +660,14 @@
           if (! stack_trace.empty ())
             std::cerr << stack_trace;
 
-          recover_from_exception ();
+          if (interactive)
+            recover_from_exception ();
+          else
+            {
+              // We should exit with a nonzero status.
+              retval = 1;
+              break;
+            }
         }
       catch (const std::bad_alloc&)
         {
@@ -1053,12 +1048,13 @@
 
       if (nargin > 1)
         {
-          return_output = args(1).is_true ();
-
-          if (error_state)
+          try
+            {
+              return_output = args(1).is_true ();
+            }
+          catch (const octave_execution_exception&)
             {
               error ("system: RETURN_OUTPUT must be boolean value true or false");
-              return retval;
             }
         }
 
--- a/libinterp/octave-value/ov-base.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/octave-value/ov-base.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -458,22 +458,25 @@
   { \
     T retval = 0; \
  \
-    double d = double_value (frc_str_conv); \
+    double d; \
  \
-    if (! error_state) \
+    try \
+      { \
+        d = double_value (frc_str_conv); \
+      } \
+    catch (const octave_execution_exception&) \
       { \
-        if (require_int && D_NINT (d) != d) \
-          error_with_cfn ("conversion of %g to " #T " value failed", d); \
-        else if (d < std::numeric_limits<T>::min ()) \
-          retval = std::numeric_limits<T>::min (); \
-        else if (d > std::numeric_limits<T>::max ()) \
-          retval = std::numeric_limits<T>::max (); \
-        else \
-          retval = static_cast<T> (::fix (d));  \
+        gripe_wrong_type_arg ("octave_base_value::" #F "_value ()", type_name ()); \
       } \
+ \
+    if (require_int && D_NINT (d) != d) \
+      error_with_cfn ("conversion of %g to " #T " value failed", d); \
+    else if (d < std::numeric_limits<T>::min ()) \
+      retval = std::numeric_limits<T>::min (); \
+    else if (d > std::numeric_limits<T>::max ()) \
+      retval = std::numeric_limits<T>::max (); \
     else \
-      gripe_wrong_type_arg ("octave_base_value::" #F "_value ()", \
-                            type_name ()); \
+      retval = static_cast<T> (::fix (d)); \
  \
     return retval; \
   }
@@ -493,24 +496,21 @@
 int
 octave_base_value::nint_value (bool frc_str_conv) const
 {
-  int retval = 0;
+  double d;
 
-  double d = double_value (frc_str_conv);
-
-  if (! error_state)
+  try
+    {
+      d = double_value (frc_str_conv);
+    }
+  catch (const octave_execution_exception&)
     {
-      if (xisnan (d))
-        {
-          error ("conversion of NaN to integer value failed");
-          return retval;
-        }
+      gripe_wrong_type_arg ("octave_base_value::nint_value ()", type_name ());
+    }
 
-      retval = static_cast<int> (::fix (d));
-    }
-  else
-    gripe_wrong_type_arg ("octave_base_value::nint_value ()", type_name ());
+  if (xisnan (d))
+    error ("conversion of NaN to integer value failed");
 
-  return retval;
+  return static_cast<int> (::fix (d));
 }
 
 double
--- a/libinterp/octave-value/ov-cell.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/octave-value/ov-cell.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -128,12 +128,6 @@
 
 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell", "cell");
 
-static void
-gripe_failed_assignment (void)
-{
-  error ("assignment to cell array failed");
-}
-
 octave_value_list
 octave_cell::subsref (const std::string& type,
                       const std::list<octave_value_list>& idx,
@@ -349,13 +343,8 @@
         else
           octave_base_matrix<Cell>::assign (i, Cell (t_rhs));
 
-        if (! error_state)
-          {
-            count++;
-            retval = octave_value (this);
-          }
-        else
-          gripe_failed_assignment ();
+        count++;
+        retval = octave_value (this);
       }
       break;
 
@@ -387,13 +376,8 @@
         else
           gripe_nonbraced_cs_list_assignment ();
 
-        if (! error_state)
-          {
-            count++;
-            retval = octave_value (this);
-          }
-        else
-          gripe_failed_assignment ();
+        count++;
+        retval = octave_value (this);
       }
       break;
 
--- a/libinterp/octave-value/ov-fcn-handle.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/octave-value/ov-fcn-handle.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -1718,86 +1718,81 @@
 
   if (args.length () == 1)
     {
-      octave_fcn_handle *fh = args(0).fcn_handle_value ();
-
-      if (! error_state)
-        {
-          octave_function *fcn = fh ? fh->function_value () : 0;
+      octave_fcn_handle *fh = args(0).fcn_handle_value ("functions: FCN_HANDLE argument must be a function handle object");
 
-          if (fcn)
-            {
-              octave_scalar_map m;
-
-              std::string fh_nm = fh->fcn_name ();
+      octave_function *fcn = fh ? fh->function_value () : 0;
 
-              if (fh_nm == octave_fcn_handle::anonymous)
-                {
-                  std::ostringstream buf;
-                  fh->print_raw (buf);
-                  m.setfield ("function", buf.str ());
-
-                  m.setfield ("type", "anonymous");
-                }
-              else
-                {
-                  m.setfield ("function", fh_nm);
+      if (fcn)
+        {
+          octave_scalar_map m;
 
-                  if (fcn->is_subfunction ())
-                    {
-                      m.setfield ("type", "subfunction");
-                      Cell parentage (dim_vector (1, 2));
-                      parentage.elem (0) = fh_nm;
-                      parentage.elem (1) = fcn->parent_fcn_name ();
-                      m.setfield ("parentage", octave_value (parentage));
-                    }
-                  else if (fcn->is_private_function ())
-                    m.setfield ("type", "private");
-                  else if (fh->is_overloaded ())
-                    m.setfield ("type", "overloaded");
-                  else
-                    m.setfield ("type", "simple");
-                }
-
-              std::string nm = fcn->fcn_file_name ();
-
-              if (fh_nm == octave_fcn_handle::anonymous)
-                {
-                  m.setfield ("file", nm);
-
-                  octave_user_function *fu = fh->user_function_value ();
+          std::string fh_nm = fh->fcn_name ();
 
-                  std::list<symbol_table::symbol_record> vars
-                    = symbol_table::all_variables (fu->scope (), 0);
-
-                  size_t varlen = vars.size ();
+          if (fh_nm == octave_fcn_handle::anonymous)
+            {
+              std::ostringstream buf;
+              fh->print_raw (buf);
+              m.setfield ("function", buf.str ());
 
-                  if (varlen > 0)
-                    {
-                      octave_scalar_map ws;
-                      for (std::list<symbol_table::symbol_record>::const_iterator
-                           p = vars.begin (); p != vars.end (); p++)
-                        {
-                          ws.assign (p->name (), p->varval (0));
-                        }
-
-                      m.setfield ("workspace", ws);
-                    }
-                }
-              else if (fcn->is_user_function () || fcn->is_user_script ())
-                {
-                  octave_function *fu = fh->function_value ();
-                  m.setfield ("file", fu->fcn_file_name ());
-                }
-              else
-                m.setfield ("file", "");
-
-              retval = m;
+              m.setfield ("type", "anonymous");
             }
           else
-            error ("functions: FCN_HANDLE is not a valid function handle object");
+            {
+              m.setfield ("function", fh_nm);
+
+              if (fcn->is_subfunction ())
+                {
+                  m.setfield ("type", "subfunction");
+                  Cell parentage (dim_vector (1, 2));
+                  parentage.elem (0) = fh_nm;
+                  parentage.elem (1) = fcn->parent_fcn_name ();
+                  m.setfield ("parentage", octave_value (parentage));
+                }
+              else if (fcn->is_private_function ())
+                m.setfield ("type", "private");
+              else if (fh->is_overloaded ())
+                m.setfield ("type", "overloaded");
+              else
+                m.setfield ("type", "simple");
+            }
+
+          std::string nm = fcn->fcn_file_name ();
+
+          if (fh_nm == octave_fcn_handle::anonymous)
+            {
+              m.setfield ("file", nm);
+
+              octave_user_function *fu = fh->user_function_value ();
+
+              std::list<symbol_table::symbol_record> vars
+                = symbol_table::all_variables (fu->scope (), 0);
+
+              size_t varlen = vars.size ();
+
+              if (varlen > 0)
+                {
+                  octave_scalar_map ws;
+                  for (std::list<symbol_table::symbol_record>::const_iterator
+                         p = vars.begin (); p != vars.end (); p++)
+                    {
+                      ws.assign (p->name (), p->varval (0));
+                    }
+
+                  m.setfield ("workspace", ws);
+                }
+            }
+          else if (fcn->is_user_function () || fcn->is_user_script ())
+            {
+              octave_function *fu = fh->function_value ();
+              m.setfield ("file", fu->fcn_file_name ());
+            }
+          else
+            m.setfield ("file", "");
+
+          retval = m;
         }
       else
-        error ("functions: FCN_HANDLE argument must be a function handle object");
+        error ("functions: FCN_HANDLE is not a valid function handle object");
     }
   else
     print_usage ();
@@ -1817,9 +1812,9 @@
 
   if (args.length () == 1)
     {
-      octave_fcn_handle *fh = args(0).fcn_handle_value ();
+      octave_fcn_handle *fh = args(0).fcn_handle_value ("func2str: FCN_HANDLE argument must be a function handle object");
 
-      if (! error_state && fh)
+      if (fh)
         {
           std::string fh_nm = fh->fcn_name ();
 
--- a/libinterp/octave-value/ov.cc	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/octave-value/ov.cc	Mon Nov 23 20:50:07 2015 -0500
@@ -1391,25 +1391,6 @@
   return rep->do_multi_index_op (nargout, idx, lvalue_list);
 }
 
-#if 0
-static void
-gripe_assign_failed (const std::string& on, const std::string& tn1,
-                     const std::string& tn2)
-{
-  error ("assignment failed for '%s %s %s'",
-         tn1.c_str (), on.c_str (), tn2.c_str ());
-}
-#endif
-
-static void
-gripe_assign_failed_or_no_method (const std::string& on,
-                                  const std::string& tn1,
-                                  const std::string& tn2)
-{
-  error ("assignment failed, or no method for '%s %s %s'",
-         tn1.c_str (), on.c_str (), tn2.c_str ());
-}
-
 octave_value
 octave_value::subsasgn (const std::string& type,
                         const std::list<octave_value_list>& idx,
@@ -1451,13 +1432,7 @@
         error ("in computed assignment A(index) OP= X, A must be defined first");
     }
 
-  octave_value tmp = subsasgn (type, idx, t_rhs);
-
-  if (error_state)
-    gripe_assign_failed_or_no_method (assign_op_as_string (op_asn_eq),
-                                      type_name (), rhs.type_name ());
-  else
-    *this = tmp;
+  *this = subsasgn (type, idx, t_rhs);
 
   return *this;
 }
@@ -2025,6 +2000,15 @@
 XVALUE_EXTRACTOR (Array<float>, xfloat_vector_value, float_vector_value)
 XVALUE_EXTRACTOR (Array<FloatComplex>, xfloat_complex_vector_value, float_complex_vector_value)
 
+XVALUE_EXTRACTOR (octave_function *, xfunction_value, function_value)
+XVALUE_EXTRACTOR (octave_user_function *, xuser_function_value, user_function_value)
+XVALUE_EXTRACTOR (octave_user_script *, xuser_script_value, user_script_value)
+XVALUE_EXTRACTOR (octave_user_code *, xuser_code_value, user_code_value)
+XVALUE_EXTRACTOR (octave_fcn_handle *, xfcn_handle_value, fcn_handle_value)
+XVALUE_EXTRACTOR (octave_fcn_inline *, xfcn_inline_value, fcn_inline_value)
+
+XVALUE_EXTRACTOR (octave_value_list, xlist_value, list_value)
+
 #undef XVALUE_EXTRACTOR
 
 octave_value
@@ -2484,30 +2468,35 @@
       bool result_is_str = (base.is_string () && limit.is_string ());
       bool dq_str = (base.is_dq_string () || limit.is_dq_string ());
 
-      Matrix m_base = base.matrix_value (true);
-
-      if (error_state)
+      Matrix m_base, m_limit, m_increment;
+
+      try
+        {
+          m_base = base.matrix_value (true);
+        }
+      catch (const octave_execution_exception&)
         {
           error ("invalid base value in colon expression");
-          return retval;
         }
 
-      Matrix m_limit = limit.matrix_value (true);
-
-      if (error_state)
+      try
+        {
+          m_limit = limit.matrix_value (true);
+        }
+      catch (const octave_execution_exception&)
         {
           error ("invalid limit value in colon expression");
-          return retval;
         }
 
-      Matrix m_increment = (increment.is_defined ()
-                            ? increment.matrix_value (true)
-                            : Matrix (1, 1, 1.0));
-
-      if (error_state)
+      try
+        {
+          m_increment = (increment.is_defined ()
+                         ? increment.matrix_value (true)
+                         : Matrix (1, 1, 1.0));
+        }
+      catch (const octave_execution_exception&)
         {
           error ("invalid increment value in colon expression");
-          return retval;
         }
 
       bool base_empty = m_base.is_empty ();
--- a/libinterp/octave-value/ov.h	Thu Nov 19 16:56:39 2015 -0500
+++ b/libinterp/octave-value/ov.h	Mon Nov 23 20:50:07 2015 -0500
@@ -1155,6 +1155,15 @@
 
   Array<FloatComplex> xfloat_complex_vector_value (const char *fmt, ...) const;
 
+  octave_function *xfunction_value (const char *fmt, ...) const;
+  octave_user_function *xuser_function_value (const char *fmt, ...) const;
+  octave_user_script *xuser_script_value (const char *fmt, ...) const;
+  octave_user_code *xuser_code_value (const char *fmt, ...) const;
+  octave_fcn_handle *xfcn_handle_value (const char *fmt, ...) const;
+  octave_fcn_inline *xfcn_inline_value (const char *fmt, ...) const;
+
+  octave_value_list xlist_value (const char *fmt, ...) const;
+  
   // Possibly economize a lazy-indexed value.
 
   void maybe_economize (void)