1

例外がキャッチされた場合でも、このメソッドが常に返される理由について混乱しています...エラーをログに記録した後に返されるべきではありませんか?

private def sendConfCode(sendTo)
    {

        def confCode = genConfCode()
        try
        {
            mail.sendMessage(sendTo.toString(), "Your confirmation code is", confCode)
            //insert confCode into temporary banner table?
        }
        catch(Exception e)
        {
            logIt.writeLog(e.message, Priority.ERR)
        }
        return confCode + " - " + sendTo
    }
4

2 に答える 2

1

正しいコード:

private def sendConfCode(sendTo)
    {

        def confCode = genConfCode()
        def sent=false
        try
        {

            mail.sendMessage(sendTo.toString(), "Your confirmation code is", confCode)
            //insert confCode into temporary banner table?
            sent = true
        }
    catch(Exception e)
    {
        logIt.writeLog(e.message, Priority.ERR)
    }
    return sent

}
于 2012-08-28T18:15:32.107 に答える
1

はい、エラーをログに記録した後に返されるはずです。実際に例外がスローされた場合、これはおそらくロガー構成のエラーです。

catch ブロックで実行を停止する場合は、そこから戻ります

private def sendConfCode(sendTo)
    {

        def confCode = genConfCode()
        try
        {
            mail.sendMessage(sendTo.toString(), "Your confirmation code is", confCode)
            //insert confCode into temporary banner table?
        }
        catch(Exception e)
        {
            logIt.writeLog(e.message, Priority.ERR)
            return
        }
        return confCode + " - " + sendTo
}
于 2012-08-28T18:07:49.197 に答える