Mercurial > octave
diff libinterp/corefcn/file-io.cc @ 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 | 2469d78a1d8b |
children | ee2743bd07a8 |
line wrap: on
line diff
--- 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, ,