LoginSignup
18
14

More than 5 years have passed since last update.

Ruby の exit と exit! の違い

Last updated at Posted at 2017-10-13

exit は例外処理を記述すれば処理を続行出来る。 exit! は例外処理を一切行わずプログラムを終了する。

def proc_exit
  puts "proc_exit"
  exit
rescue SystemExit
  puts "rescued a SystemExit exception"
end

def proc_exit!
  puts "proc_exit!"
  exit!
rescue SystemExit
  puts "rescued a SystemExit exception"
end

proc_exit
proc_exit!

出力

proc_exit
rescued a SystemExit exception
proc_exit!

参考サイト

18
14
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
14