help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

return intermediate result from interrupted/failed function?


From: novakyu
Subject: return intermediate result from interrupted/failed function?
Date: Wed, 28 Nov 2007 18:27:20 -0800

Hi,

I have a function that goes through a large amount of data and
analyzes them in a fashion, and I'd like it to return the result of
analysis it has at the moment, if it were ever to be interrupted, or
choke on a particular set of data, rather than losing what it has
analyzed because the very last dataset didn't get analyzed cleanly
(and escaped some internal exception handling as wel). I tried it with
try ... catch statement, where "try" encloses the step most likely to
fail (or get interrupted) and catch has simple error message, but it
doesn't seem to work as I hoped.

The function I have basically looks like:

function analysis = analyze()

.... % some interactive commands to gather data to analyze)
analysis = [];

for i=data % loops over data files
  try
    ... % analysis which includes some interactive prompts
    ... % this section also contains commands that append to
"analysis" variable.
  catch
    ... % some questions to determine whether to continue with other
data or stop
    if (stop)
      break;
    endif
  end_try_catch
endfor

But when I actually run it, let it get some analyzed data, and then
try to interrupt it with Control-C, it just quits without executing
"catch" portion above.

I also tried the setup with unwind_protect, but while it does execute
the unwind_protect_cleanup (... every single time, but that can be
fixed), when I try breakng out of the loop, again no "analysis"
variable is returned.

Is there any way to have a function return the current value even on a
... not completely-successful call?

Thank you,

Andrzej


reply via email to

[Prev in Thread] Current Thread [Next in Thread]