Hi all,
I am writing a long and complex external.
There are several conditions in which a particular function could fail and in any of those cases I'd like to report the error and stop the execution of the function.
I tried using the exit() function, but that quits pd, and what I really need is for the function to simply stop.
Does pd have a function for doing this?
best,
J
When I was a kid we used setjmp to do this... I see it's still around now and might be what you need.
cheers M
On Tue, Jun 17, 2014 at 01:17:10AM -0500, Jaime E Oliver via Pd-list wrote:
Hi all,
I am writing a long and complex external.
There are several conditions in which a particular function could fail and in any of those cases I'd like to report the error and stop the execution of the function.
I tried using the exit() function, but that quits pd, and what I really need is for the function to simply stop.
Does pd have a function for doing this?
best,
J
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On 06/17/2014 08:17 AM, Jaime E Oliver via Pd-list wrote:
Hi all,
I am writing a long and complex external.
There are several conditions in which a particular function could fail and in any of those cases I'd like to report the error and stop the execution of the function.
I tried using the exit() function, but that quits pd, and what I really need is for the function to simply stop.
Does pd have a function for doing this?
no. you would have to do this yourself.
afaik, the easiest way to do it is: if(bad_condition) { pd_error(x, "bad condition met!"); return; }
if you need to cleanup you could use: if(bad_condition) { pd_error(x, "bad condition met!"); goto fail; } // ... fail: free_ressources(x);
in general, you might want to split your complex function into small functions that returns their success, then do:
int do_A(ressource*X) { if(is_bad(X)){ error("X is bad!"); return 0; } return 1; } //... int processing() { X=make_ressource(); if(do_A(X) && do_B(X) && do_C(X)) { // success } free_ressource(X); }
when using C++, you can use exceptions...which you have to catch() in order to not-quit-Pd
fgmards IOhannes