Backend development

Stage 1 · Lesson 4 of 10

Errors and exceptions

Your language and how HTTP works

Modern PHP reports most failures as throwables, things you can and catch. An Exception is for problems your code can expect and handle. An Error is for failures inside PHP itself, such as calling a method on null, or a TypeError from .

Catch specific exception types with try and catch, and use finally for cleanup. Define your own, such as OrderNotFoundException, which 's exception handler can later turn into a in one place. In development, show every error. In production, log errors but never display them to users.

Common trapthe @ operator, which hides errors on a line along with their real cause, and an empty catch (\Throwable $e) {} that quietly swallows everything.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • VideoFree
    PHP For Beginners

    Laracasts · Beginner

    Free video series that builds a small app in plain PHP before any framework

  • GuideFree
    PHP: The Right Way

    Josh Lockhart and contributors · Intermediate

    Modern PHP practice in one place: Composer, PSR standards, PDO and security basics

Practise

  • Your language track: small exercises with free mentor feedback on idiomatic code

Keep handy

  • Quick syntax lookups for your language when you forget how something is written

  • Read the HTTP overview, methods, headers and status code pages until they feel obvious

Also worth your time

Mark this stage as not done?