[bind10-dev] whether/when to use exceptions

Ray Burkholder ray at oneunified.net
Wed Oct 14 13:37:38 UTC 2009


 
> This is why in this case it is better to use goto's:
> 
>          fp = fopen("foo.txt", "w");
>          if (fp == NULL)
> 	     goto out;
> 
>          for (i=0; i<10; i++)
>              if (fprintf(fp, "%d\n", i) < 0)
> 		 goto out;
> 
>          if (fclose(fp) != 0)
> 	     got out;
> 
>          return SUCCESS_CODE;
> out:
> 	 if (fp)
> 	     (void)fclose(fp);
> 	 remove("foo.txt");
> 	 return ERROR_CODE;
> 

Of if you are allowing Boost into the code, the ScopeExit library may be of
value:
http://www.boost.org/doc/libs/1_40_0/libs/scope_exit/doc/html/scope_exit/alt
ernatives.html


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the bind10-dev mailing list