Advanced Octave A63 — Error handling and resource cleanup

by Giux GX-TXT, octave-en, scripts-en 1 min read

Advanced GNU Octave with GX-TXT · Module 11

An error during an analysis should not leave unnecessarily recorded resources or hide the initial cause. We simulate a size error and check the release of a callback.

Objectives and prerequisites

We repeat the callbacks of the non-linear estimate of A52. The test uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0. Import risorse.m, register it and run it in the Runner.

Provoking a controlled error

The program records a callback and intentionally defines x with three values and y with two. The length verification generates the Course:LengthMismatch error before the fit call. The unwind_protect_cleanup lock still attempts to release the callback; a cleaning error is reported separately on stderr, so it does not replace the original error.

The external catch intercepts the original error to complete this demonstration and show the sequence in the Runner:

The press test that the callback was released, then reports Course:LengthMismatch; no fit is performed. The final status of the Job is completed because the demonstration error has been intentionally intercepted. In a real analysis, if the error prevents the required result, after cleaning it is generally necessary to relaunch it with rethrow(err) or communicate it so that the Job does not seem successful.

Exercise

  1. What control does it fail intentionally?
  2. When is cleaning done?
  3. Why does the example not produce an estimate?

Worked solution

  1. The lengths of X and Y are different.
  2. At the exit from the protected block, even in the presence of the error.
  3. The error is generated before the call to the fit.

Download the Module 11 scripts (ZIP)

#GNU Octave #GX-TXT #GX-TXT public APIs

Other steps of this project

Leave a Reply

Your email address will not be published. Required fields are marked *