Successive success checks

Posted by Stockhausen on Stack Overflow See other posts from Stack Overflow or by Stockhausen
Published on 2010-05-03T06:39:49Z Indexed on 2010/05/03 6:48 UTC
Read the original article Hit count: 106

Filed under:

Most of you have probably bumped into a situation, where multiple things must be in check and in certain order before the application can proceed, for example in a very simple case of creating a listening socket (socket, bind, listen, accept etc.). There are at least two obvious ways (don't take this 100% verbatim):

if (1st_ok)
{
  if (2nd_ok)
  {
  ...

or

if (!1st_ok)
{
  return;
}

if (!2nd_ok)
{
  return;
}
...

Have you ever though of anything smarter, do you prefer one over the other of the above, or do you (if the language provides for it) use exceptions?

© Stack Overflow or respective owner

Related posts about best-practices