Skip to content

Error handling with return codes

Handout

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.

A function returns 0 on success or -1 on failure; the caller checks the code

Handout

Log in or create account

IGCSE & A-Level