Go Down

Topic: Using the RDM630 RFID Tag Reader and NewSoftwareSerial library (Read 4 times) previous topic - next topic

pekkaa

#35
Nov 01, 2012, 04:03 pm Last Edit: Nov 01, 2012, 04:05 pm by pekkaa Reason: 1
I don't want to start a flame war here, but there are some rare occasions where using gotos is justified (OP's example was obviously not one of those). I have sometimes used gotos as a kind of a exception throwing mechanism where it makes handing error conditions  simpler. Something like:

Code: [Select]

int foo()
{
   int ret;
   if (!(ret = do_something())) goto err;
   
   ...

   if (!(ret = do_something_else())) goto err;
   if (!(ret = do_something_more())) goto err;

   return OK;

 err:
   rollback();
   show_error_message();
   return ERR;
}




Nick Gammon

That was what try/throw/catch was added for in recent times. Not supported under the compile options used by the IDE however.

pekkaa

I tend to use goto exception throwing in languages that don't support actual try/catch/throw mechanism, such as in Perl and vanilla C. I have to say that try/catch/throw exception handling is not any of my favorite features. It is especially irritating in Java, which forces to catch exceptions is cases where I would rather just let the program crash.

Go Up