[Kde-pim] if else construct detecting errors

Allen Winter winter at kde.org
Mon Nov 25 14:07:07 GMT 2013


Sandro,

KMail says "Invalid signature" in red for this message.

I did an update build this morning, so I'm hoping your commits yesterday
didn't introduce a regression.

another bug?
 


On Monday, November 25, 2013 01:04:33 PM Sandro Knauß wrote:
> 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
> }

_______________________________________________
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