Advanced Octave A63 — Error handling and resource cleanup
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
- What control does it fail intentionally?
- When is cleaning done?
- Why does the example not produce an estimate?
Worked solution
- The lengths of X and Y are different.
- At the exit from the protected block, even in the presence of the error.
- The error is generated before the call to the fit.
Other steps of this project
- Advanced Octave A75 — Dynamical systems in phase space
- Advanced Octave A81 — Geography of the waves and a 3D surface
- Advanced Octave A82 — Age, sex and demographic inequalities
- Advanced Octave A83 — All-cause mortality, certified COVID deaths and surveillance
- Advanced Octave A84 — A reproducible public account
- Advanced Octave A73 — Optimization landscapes and 3D trajectories