elixir - 18 try-catch-rescue
访问量: 1336
参考:https://elixir-lang.org/getting-started/try-catch-and-rescue.html
跟Ruby确实很像(现在终于开始像)
#raise "hi" # try do raise "lalala" rescue e in RuntimeError -> e IO.puts e end # 通常不用try rescue/catch, 在代码中做处理。 case File.read "hello" do ...> {:ok, body} -> IO.puts "Success: #{body}" ...> {:error, reason} -> IO.puts "Error: #{reason}" ...> end # 使用exit 来退出当前Process iex(1)> spawn_link fn -> exit(3) end ** (EXIT from #PID<0.103.0>) shell process exited with reason: 3 Interactive Elixir (1.8.1) - press Ctrl+C to exit (type h() ENTER for help)