Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use exceptions in CakePHP?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 550
    Comment on it

    Hi Reader's,
    Welcome to FindNerd, today we are going to discuss exceptions in CakePHP.

    We can use exceptions for a variety of uses in our application when implementing any web application in CakePHP. CakePHP uses the exceptions internally to show the logical cake PHP errors and all exceptions occur in CakePHP when CakeException is raised.  

    Note:- we can use error handler to catch uncaught exceptions from controllers and other parts of our application

    CakePHP has numbers of exception classes that we can use for HTTP errors.

    For configuring exceptions in CakePHP, we can use the below code.

    <?php 
        Configure::write('Exception', array(
        'handler' => 'ErrorHandler::handleException',//The callback to handle exceptions. You can set this to any callback type,
        'renderer' => 'ExceptionRenderer',// The class responsible for rendering uncaught exceptions.
        'log' => true // boolean - When true, exceptions + their stack traces will be logged to CakeLog.
        ));
    ?>
    

    If we change the handler then this change will allow us to take full control over the exception handling process. If we change the renderer, then it will allow us to change the output.

     

    Detail of exception classes

    There are a number of exception classes in CakePHP. Each exception replaces a cakeError() error messages.

    There are several built-in exceptions inside CakePHP

    1-Exception BadRequestException :- This exception is used for doing 400 Bad Request error.

    2-Exception UnauthorizedException:- This exception is used for doing a 401 Unauthorized error.

    3-Exception ForbiddenException :- This exception is used for doing a 403 Forbidden error.

    4-Exception NotFoundException:- This exception is used for doing a 404 Not found error.

    5-Exception MethodNotAllowedException:- This exception is used for doing a 405 Method Not Allowed error.

    6-Exception InternalErrorException :- This exception is used for doing a 500 Internal Server Error.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: