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