How to add a custom exception on symfony2

后端 未结 4 391
有刺的猬
有刺的猬 2020-12-09 21:11

I am new to Symfony(using version 2.2) and trying to add a custom exception listener. I have read the following links but cannot get it to work.

  • Overriding Sym
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 21:34

    You can create custom exception the "symfony way" let's look at how exception or created in symfony:

    first create your customExceptionInterface

    namespace My\SymfonyBundle\Exception;
    /**
     * Interface for my bundle exceptions.
     */
    interface MySymfonyBundleExceptionInterface
    {
    }
    

    And create your jsonErrorException

    namespace My\SymfonyBundle\Exception;
    
    class HttpException extends \Exception implements MySymfonyBundleExceptionInterface
    {
    }
    

    Don't hesitate to browse symfony's exceptions code examples on github

提交回复
热议问题