[PD] exiting function in external

IOhannes m zmölnig via Pd-list pd-list at lists.iem.at
Tue Jun 17 13:27:27 CEST 2014

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!");

if you need to cleanup you could use:
  if(bad_condition) {
      pd_error(x, "bad condition met!");
      goto fail;
  // ...

in general, you might want to split your complex function into small
functions that returns their success, then do:

int do_A(ressource*X) {
     error("X is bad!");
     return 0;
  return 1;
int processing() {
  if(do_A(X) && do_B(X) && do_C(X)) {
     // success

when using C++, you can use exceptions...which you have to catch() in
order to not-quit-Pd


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 880 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20140617/b67620a4/attachment.sig>

More information about the Pd-list mailing list