Throw From Finally (ARCH6155)
هذا المحتوى غير متوفر بلغتك بعد.
Key ruby.logging.raise-in-ensure · Severity error · Category logging
Raising inside an ensure block masks any in-flight exception from the begin body and loses the real failure. Cleanup code must not raise.
Incorrect
Section titled “Incorrect”def write(file) file.write(data)ensure raise "Could not close stream" unless file.closeendCorrect
Section titled “Correct”def write(file) file.write(data)ensure begin file.close rescue => e Rails.logger.warn("Could not close stream", exception: e) endendCatch and log cleanup errors inside the ensure block; do not raise from there.