Elixir/Phoenix handling erlang errors

Ilya

I'm using System.cmd command to work with a file. However if the files is not found on the system, it raises ArgumentError, specifically Erlang error: :enoent. How can I handle this error with the case function? Here is my code so far:

case System.cmd(generate_executable(settings), ["start"]) do
  {output, 0} ->
    IO.inspect("Start successful")
  {output, error_code} ->
    IO.inspect("Start failed")
end

This cases work for mistakes from OS (whether is starts or not), but not for the erlang errors, resulting in phoenix telling me about :enoent. enter image description here

Dogbert

You'll have to use try/rescue.

try do
  case System.cmd(generate_executable(settings), ["start"]) do
    {output, 0} ->
      IO.inspect("Start successful")
    {output, error_code} ->
      IO.inspect("Start failed")
  end
rescue
  error ->
    IO.inspect(error)
end

When the executable does not exist, you should see %ErlangError{original: :enoent} printed by the IO.inspect in rescue.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Handling two consecutive errors

分類Dev

Handling multiple errors in go

分類Dev

Catching and handling backend errors in Angular

分類Dev

handling unicode encode errors in python

分類Dev

Handling Errors in PocketSphinx Android app

分類Dev

Handling errors with clojure core.async pipeline

分類Dev

Handling AWS Lambda errors with API Gateway

分類Dev

Customize errors handling in uu-parsinglib in Haskell

分類Dev

Azure Webjobs SDK and Queue handling errors

分類Dev

$http error handling: distinguishing user offline from other errors

分類Dev

Handling Chromecast load errors in web-based sender

分類Dev

msal.js angular 6 SPA callback and errors handling

分類Dev

react-hook-form handling server-side errors in handleSubmit

分類Dev

Elixirphoenix.serverのデバッグ

分類Dev

phx.gen.jsonコマンドでのElixirPhoenixの問題

分類Dev

ElixirPhoenixのオプションのPOSTパラメーター

分類Dev

Elixirphoenixのログアウトリンクが機能しない

分類Dev

関連するモデルリストのElixirPhoenixヘルパー

分類Dev

Elixirphoenixのライブリロードが機能しない

分類Dev

「params」に一致するElixirPhoenixパターン

分類Dev

ERLANG + IF + BOOLEAN

分類Dev

ElixirPhoenixのフラッシュメッセージが表示されない

分類Dev

プロトコルPhoenix.HTML.Safeは実装されていませんElixirPhoenix

分類Dev

ElixirPhoenixの更新ネストされた多対多の関連付け

分類Dev

postgresql elixirphoenixに接続していない蒸留所のビルド

分類Dev

Eメールを送信するためのCSSをインライン化するElixirPhoenix

分類Dev

elixirphoenixアプリでバックグラウンドジョブを作成する正しい方法

分類Dev

Docker内のリモートElixirPhoenixサーバーでErlangObserverアプリを使用する

分類Dev

関数nil.email/0は、elixirphoenixでは未定義またはプライベートです

Related 関連記事

  1. 1

    Handling two consecutive errors

  2. 2

    Handling multiple errors in go

  3. 3

    Catching and handling backend errors in Angular

  4. 4

    handling unicode encode errors in python

  5. 5

    Handling Errors in PocketSphinx Android app

  6. 6

    Handling errors with clojure core.async pipeline

  7. 7

    Handling AWS Lambda errors with API Gateway

  8. 8

    Customize errors handling in uu-parsinglib in Haskell

  9. 9

    Azure Webjobs SDK and Queue handling errors

  10. 10

    $http error handling: distinguishing user offline from other errors

  11. 11

    Handling Chromecast load errors in web-based sender

  12. 12

    msal.js angular 6 SPA callback and errors handling

  13. 13

    react-hook-form handling server-side errors in handleSubmit

  14. 14

    Elixirphoenix.serverのデバッグ

  15. 15

    phx.gen.jsonコマンドでのElixirPhoenixの問題

  16. 16

    ElixirPhoenixのオプションのPOSTパラメーター

  17. 17

    Elixirphoenixのログアウトリンクが機能しない

  18. 18

    関連するモデルリストのElixirPhoenixヘルパー

  19. 19

    Elixirphoenixのライブリロードが機能しない

  20. 20

    「params」に一致するElixirPhoenixパターン

  21. 21

    ERLANG + IF + BOOLEAN

  22. 22

    ElixirPhoenixのフラッシュメッセージが表示されない

  23. 23

    プロトコルPhoenix.HTML.Safeは実装されていませんElixirPhoenix

  24. 24

    ElixirPhoenixの更新ネストされた多対多の関連付け

  25. 25

    postgresql elixirphoenixに接続していない蒸留所のビルド

  26. 26

    Eメールを送信するためのCSSをインライン化するElixirPhoenix

  27. 27

    elixirphoenixアプリでバックグラウンドジョブを作成する正しい方法

  28. 28

    Docker内のリモートElixirPhoenixサーバーでErlangObserverアプリを使用する

  29. 29

    関数nil.email/0は、elixirphoenixでは未定義またはプライベートです

ホットタグ

アーカイブ