Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////
- // method 1
- // stuff that can go wrong;
- if (test1 == failed)
- {
- // print error;
- // exit;
- }
- else
- {
- // more stuff that can go wrong;
- if (test2 == failed)
- {
- // print error;
- // exit;
- }
- else
- {
- // ... and so on...
- }
- }
- ///////////////////////////////////////////
- // method 2
- // stuff that can go wrong;
- if (test1 == failed)
- {
- // print error;
- // exit;
- }
- // more stuff that can go wrong;
- if (test2 == failed)
- {
- // print error;
- // exit;
- }
- // ... and so on...
- if (0)
- {
- ERROR:
- // Handle errors, and exit/return after potentially freeing resources
- }
- #define LOCAL_ASSERT(COND) if (COND) {
- /* Handle errors, and exit/return after potentially freeing resources */
- }
- // method 1
- if (error) goto ERROR; // no else
- // method 2
- LOCAL_ASSERT(cond);
- if (test1 == failed)
- {
- // print error;
- // exit;
- }
- else if (test2 == failed)
- {
- // print error;
- // exit;
- }
- else
- {
- // ... and so on...
- }
- const Bool funcFoo(int someval, int someval2, int someval3)
- {
- if(someval == okval)
- { // We're ok
- if(someval2 == okval2)
- { // Still ok.
- if(someval3 == okval3)
- { // Yippee! We made it!
- return True; // <===== ONLY SUCCESS RETURN POINT
- }
- }
- }
- // Houston, we had a problem.
- return False; // <===== ONLY FAIL RETURN POINT
- }
- const Bool funcFoo(int someval, int someval2, int someval3)
- {
- if(someval == okval)
- { // We're ok
- if(someval2 == okval2)
- { // Still ok.
- if(someval3 == okval3)
- { // Yippee! We made it!
- return True; // <===== ONLY SUCCESS RETURN POINT
- }
- else
- { // someval3 is bad.
- //...maybe handle, not return.
- }
- }
- else
- { // someval2 is bad.
- // ...maybe handle, not return.
- }
- }
- else
- { // someval is bad.
- // ...maybe handle, not return.
- }
- // Houston, we had a problem.
- return False; // <===== ONLY FAIL RETURN POINT
- }
Add Comment
Please, Sign In to add comment