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');
}