从catch块groovy返回

从catch块groovy返回,groovy,Groovy,我不明白为什么即使捕获到异常,这个方法也总是返回。。。它不应该在记录错误后返回吗 private def sendConfCode(sendTo) { def confCode = genConfCode() try { mail.sendMessage(sendTo.toString(), "Your confirmation code is", confCode) //insert co

我不明白为什么即使捕获到异常,这个方法也总是返回。。。它不应该在记录错误后返回吗

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
    }

是的,它应该在记录错误后返回,如果确实引发了异常,则这可能是记录器配置中的错误

如果希望执行在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
}
正确代码:

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

}

您如何知道抛出了异常?应用system out并查看是否捕获了异常,如果是,则是日志错误,为什么在捕获异常后它不会返回?或者你的意思是,它不是特别写信息(和刷新它等等),我知道我得到了一个例外。我希望执行停止在catch块中。我觉得自己很愚蠢。。。重新构造了方法,让它做我想做的事情。