0

How to handle errors in symfony2 using try catch and store the error in custom db table like we do in C#.

eg

try
{
     // code with exception.
}
catch(Exception ex)
{
    //get the error and store information in table
} 

1 Answer 1

0

You can use the PHP try-catch block to catch exceptions as you mentioned. You can have a look to this answer: How to catch Exception in symfony 2?

With this method you can catch exceptions for the given code block. If you want to catch all exceptions in generally, then you should write an EventListener class, that will be fired if any uncatched exception occurs.

In the Symfony2 cookbook there is an example of writing an exception handler class: How to create an Event Listener

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

3 Comments

Thank you very much i will try both the steps you have stated above and let you if i have any doubts.
does eventListener does not work for fatelexception that accur in system.
From Symfony 2.3 there is a built-in component called Debug: symfony.com/doc/master/components/debug/introduction.html You can set up a function that handles errors and converts them to exceptions, and then you can catch theese FatalErrorExceptions.

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.