[Kde-pim] if else construct detecting errors

Sandro Knauß mail at sandroknauss.de
Mon Nov 25 12:04:33 GMT 2013


Hey,

I wanted to know if there is a rule how to handle else constructs, when 
detecting errors. There are two cases to handle them. One is to use an else 
clause and the other is to exit the function directly in the if and stops 
futher processing.

IMHO the version to return directly is better readable and understandable. If 
I see a return i know, ok, now the function returns. If there is this big else 
clause behind, i have to look behind it to see if there is anything.

sandro

Here two possibilities:

with else clause

(messagecomposer/job/signjob.cpp line 241)

  if ( res.error() ) {
     // [...] Removed
     setError( res.error().code() );
     setErrorText( QString::fromLocal8Bit( res.error().asString() ) );
  } else {
    QByteArray signatureHashAlgo =  res.createdSignature( 0 
).hashAlgorithmAsString();
    d->resultContent = MessageComposer::Util::composeHeadersAndBody( d-
>content, signature, d->format, true, signatureHashAlgo );
  }

  emitResult();
  return; //Added to better understand
}


without else clause:

    if ( res.error() ) {
        // [...] Removed
        setError( res.error().code() );
        setErrorText( QString::fromLocal8Bit( res.error().asString() ) );
        emitResult();
        return;
    }

    QByteArray signatureHashAlgo =  res.createdSignature( 0 
).hashAlgorithmAsString();
    d->resultContent = MessageComposer::Util::composeHeadersAndBody( d-
>content, signature, d->format, true, signatureHashAlgo );

  emitResult();
  return; //Added to better understand
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20131125/48a6941d/attachment.sig>
-------------- next part --------------
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/


More information about the kde-pim mailing list