throw giving error message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joeschoe
    New Member
    • Jan 2012
    • 6

    throw giving error message

    I an getting the following error:
    PHP Parse error: parse error, unexpected T_STRING in errtest.php on line 7

    The code is a sample from w3schools:
    Code:
    <?php
     //create function with an exception
     function checkNum($number)
       {
       if($number>1)
         {
         throw new Exception("Value must be 1 or below");
         }
       return true;
       }
     
    //trigger exception
     checkNum(2);
     ?>
    I am using php5 and developting on Javascriptedito r
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Are you sure you're using php 5.1 or above?

    call phpinfo(); at the top of your file to check.

    dan

    Comment

    • joeschoe
      New Member
      • Jan 2012
      • 6

      #3
      I am using php 5.2.17

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        I copy and pasted your code. It works as expected. A Fatal error occurs because the exception is thrown. I didn't see your T_STRING error. Check to make sure you're working with the latest code.

        Dan

        Comment

        • joeschoe
          New Member
          • Jan 2012
          • 6

          #5
          Originally posted by dlite922
          I copy and pasted your code. It works as expected. A Fatal error occurs because the exception is thrown. I didn't see your T_STRING error. Check to make sure you're working with the latest code.

          Dan
          You are correct. my editor has a built in PHP checker that is not up-to-date.
          Your insisting that the code is correct forced me to sharpen my pencil abit more and get to the bottom of this

          Thank you for your effort.

          Comment

          Working...