0

This is sample code to catch error in PHP.

<?php
// Error handler function.
function customError($errno, $errstr)
{
    echo "<b>Error:</b> [$errno] $errstr";
}

// Set error handler.
set_error_handler('customError');

// Trigger error.
echo($test);
?> 

I am using frameworks. i dont know how to log errors. I tried by giving function customError($errno, $errstr) in modal and I called from controller it doesn't work for me. How to handle error in frameworks?

2
  • 5
    You should probably tell us what framework you are using. Commented Dec 16, 2010 at 14:36
  • 3
    you've got to at least say which framework! Commented Dec 16, 2010 at 14:37

1 Answer 1

1

The best approach is to throw exception. Inside your main execution loop catch exceptions and output them into log file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.