パラメータをドメイン インスタンスにバインドし、それを永続化を処理するサービスに渡す、かなり単純な Grails コントローラ アクションがあります。
def finishBooking() {
Booking booking = new Booking(params)
try {
booking = bookingService.saveBooking(booking)
} catch (ReservationException e) {
log.error("Error saving booking", e)
flash.message = "Couldn't save the reservation."
render(view: "index", model: [booking: booking])
return
}
if (booking.hasErrors()) {
flash.message = "Reservation failed. Check the required fields."
render(view: "index", model: [booking: booking])
} else {
[booking: booking]
}
}
codenarcによると、catch ブロック内の return ステートメントは悪い習慣です。他にどのようにエラー処理を実装しますか?