Try-Catch with C.

How would I write a simulated try-catch block to shelter file streams in C? C sucks.

Posted Feb 4, 2013, 6:39 AM UTC

53
Gravemind123•

There isn't a good C replacement for try/catch that I am aware of. There is something called like longjmp and setjmp that you can build a similar structure with.

Are you using POSIX methods on a Unix platform? If so all of those methods either have return values or set something when they error.

3
IlluminatesfollyOP•

yeah I ended up using setjmp longjmp to do it, but it didn't feel right- I feel dirty now.

3
cokeisahelluvadrug•

I think system calls work differently depending on what OS you're using, it's pretty much a case-by-case thing

3