Error handling and the exec

Some programmer's show off: They don't use an if condition to check whether the exec API failed; they just write the line of code after an exec to be the failure case!

As an example, take the previous program, but change the code to this, the wrong way to do it:

execl("/bin/uname", "uname", argv[1], (char *)0);
FATAL("execl failed ");

It works, yes: The only reason control will ever reach the 'FATAL()' line is if the exec operation failed. This sounds cool, but please, do not code like that. Be professional, follow the rules and good coding style guidelines; you'll be a better programmer and glad for it! (An innocent freshly minted programmer might not even realize that what follows the execl above is actually error handling; who could blame him? And he might attempt to put some business logic there!)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset