コンテンツへスキップ

Error handling with return codes

English

C has no try/except

  • Some languages throw exceptions when something goes wrong. C does not have exceptions.
  • Instead, a C function reports trouble through its return value — a status code.
  • The caller checks that code after every call and decides what to do.

save_file returns 0 when it worked and -1 when it failed; the caller checks the code

プリント

ログインまたはアカウント作成

IGCSE, A-Level & AP