Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
CodeIgniter

Error Handling in CodeIgniter

Handle exceptions and show friendly errors in development vs production.

Error Handling in CodeIgniter — a practical guide to CodeIgniter error handling with clear examples you can reuse in real projects.

CodeIgniter Tutorial Series (58/74). Prefer one article? Read the complete CodeIgniter tutorial.

Short description

Use try/catch for expected failures and let CI’s exception handler manage unexpected errors. Keep `CI_ENVIRONMENT=production` on live servers.

Try/catch example

try {
    $db->transException(true)->transStart();
    // queries...
    $db->transComplete();
} catch (Throwable $e) {
    log_message('error', $e->getMessage());
    return redirect()->back()->with('error', 'Something went wrong');
}

Leave a reply

Your email address will not be published. Required fields are marked *