Exception handling - Undefined offset does not throw exception

Discussion in 'PHP' started by jkl6, Jan 11, 2011.

  1. #1
    I'm wondering why this PHP code doesn't generate an exception like Java. Essentially, I'm trying to access an empty array, which would generate an index out of bound exception in Java. In PHP, I get "Notice: Undefined offset: 1 in xxxxx.php on line xx" instead and my script continues to finish.

    $myarray = array();
    try {
       echo $myarray[1];
       echo "DONE";
    } catch(Exception $e) {
       echo "EXCEPTION!!!";
    }
    Code (markup):
     
    jkl6, Jan 11, 2011 IP
  2. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #2
    Notice does not throw exception afaik. Error and warning do not throw exception too :)
     
    xrvel, Jan 11, 2011 IP