Ruby 2.0
为什么下面的代码会给出意外的返回(LocalJumpError)?
# some code here
puts "Scanning for xml files .."
zip_files = Dir.entries(directory).select { |f| File.extname(f) == '.zip' }
if(zip_files.count == 0)
puts "No files found, exiting..."
return
end
# more code here ( if files found)
Error: unexpected return (LocalJumpError)
No files found, exiting...
[Finished in 0.9s with exit code 1]
答案 0 :(得分:6)
答案 1 :(得分:0)
或者,您可以营救LocalJumpError
puts "Scanning for xml files .."
zip_files = Dir.entries(directory).select { |f| File.extname(f) == '.zip' }
begin
return unless zip_files.count > 0
# more code here ( if files found)
rescue LocalJumpError
puts "No files found, exiting..."
end