Results 1 to 6 of 6

Thread: Exceptions of PHP in set_exception_handler?

  1. #1
    Join Date
    Aug 2006
    Posts
    122

    Exceptions of PHP in set_exception_handler?

    Hi friends,
    I have done a PHP programming language to some extent. Now I am developing some lower end code in my system. Where this code uses multiple child classes of the php exception class. I am not having much idea of set_exception_handler unless I can set the function to be a method of an object. I tried to search on web but didn't got any appropriate answers. So thought that posting here would be useful. Please tell me something about the Exceptions of PHP in set_exception_handler?. Hope that someone would help me sooner.!!
    As you simplify your life, the laws of the universe will be simpler; solitude will not be solitude, poverty will not be poverty, nor weakness.Henry David Thoreau

  2. #2
    Join Date
    Jul 2006
    Posts
    286

    Re: Exceptions of PHP in set_exception_handler?

    You should know about the exception then you can understand the purpose of the Handler. An exception can be thrown, and caught ("catched") within PHP. You will have to write an exceptions between try and catch block. For changing the flow of the code execution if a specified error condition occurs, you will have to use an exception handler. Talking about the set_exception_handler, it sets a user-defined exception handler function. This function is used to create a way of handling exceptions during runtime.
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

  3. #3
    Join Date
    Jul 2006
    Posts
    442

    Re: Exceptions of PHP in set_exception_handler?

    Like said before, the set_exception_handler() function sets a user-defined function to handle exceptions. For creating the handling exceptions during runtime, this function is used. After using this function, the old exception handler would be returned to you. If you have not defined the handler previously in your coding then, the set_exception_handler will return some failure or Null. Hope that you got purpose of using the set_exception_handler in PHP.
    "When they give you ruled paper, write the other way..." J.R.J.

  4. #4
    Join Date
    Mar 2008
    Posts
    349

    Re: Exceptions of PHP in set_exception_handler?

    I have tried to describe more about the set_exception_handler. The syntax for an exception of PHP in set_exception_handler is as below :
    PHP Code:
    callback set_exception_handler  callback $exception_handler  
    When you use this handler, it sets the default exception handler if an exception is not caught within a try/catch block. When an exception is called, the execution will stop after the exception_handler.

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Exceptions of PHP in set_exception_handler?

    knowing about the parameters is also very important. So I have described about the details. The parameter in set_exception_handler is exception_function. This parameter is always required while writing that exception. this parameter specifies the function to be called when an uncaught exception occurs. You should also define this function before calling the set_exception_handler() function. The only one parameter is required for an exception handler, which is the exception object that was thrown.

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Exceptions of PHP in set_exception_handler?

    I think that looking at the code given below, you would understand how to use an exceptions in set_exception_handler. so just have a look at the coding below :
    PHP Code:
    <?php
    function ExcepDemo($exception)
    {
    echo 
    "<b>Exception:</b> " $exception->getMessage();
    }

    set_exception_handler('ExcepDemo');

    throw new 
    Exception('Uncaught Exception occurred');
    ?>

Similar Threads

  1. Resource Exceptions
    By shoppingboy in forum Windows Software
    Replies: 2
    Last Post: 05-03-2010, 08:40 PM
  2. Vector class and exceptions
    By Logan 2 in forum Software Development
    Replies: 5
    Last Post: 24-02-2010, 03:57 AM
  3. What are Exceptions in PHP 5?
    By DANIEL 602 in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 01:35 AM
  4. What is Log .NET Exceptions
    By Agneya in forum Software Development
    Replies: 4
    Last Post: 07-02-2010, 01:34 AM
  5. PHP Error exceptions
    By nehal_serpa in forum Software Development
    Replies: 3
    Last Post: 01-05-2009, 06:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,974,081.04476 seconds with 17 queries