sustrik/libmill

Handling runtime errors in goroutines

amitsaha opened this issue · 2 comments

Hello,

Thank you for libmill. Just been trying it out. Here is my first query: How do you handle runtime errors in a co routine so that it doesn't bring down the entire program?

A test program is as below:

# include <stdio.h>
# include <libmill.h>

coroutine void f(int index, const char *text)
{
  printf("Worker %d, Message %s\n", index, text);
  printf("%f", index/0); // This will cause the first co routine to FPE but I want the others to continue
}


int main(int argc, char **argv)
{
  char str[10];
  for(int i=0;i<=100000; i++) {
    sprintf(str, "Text %d", i);
    go(f(i, str));
  }
  return 0;
}

I guess more generally, how would I implement http://blog.golang.org/defer-panic-and-recover using libmill?

There's nothing special about llibmill. It's just a library. Handle errors as you do in C.

Cool, thanks for your reply. closing.