473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  //create function with an exception
  3.  function checkNum($number)
  4.    {
  5.    if($number>1)
  6.      {
  7.      throw new Exception("Value must be 1 or below");
  8.      }
  9.    return true;
  10.    }
  11.  
  12. //trigger exception
  13.  checkNum(2);
  14.  ?> 
  15.  
I am using php5 and developting on Javascripteditor
Jan 30 '12 #1

✓ answered 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

4 1646
dlite922
1,584 Expert 1GB
Are you sure you're using php 5.1 or above?

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

dan
Jan 30 '12 #2
I am using php 5.2.17
Jan 30 '12 #3
dlite922
1,584 Expert 1GB
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
Jan 31 '12 #4
@dlite922
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.
Jan 31 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Toni | last post by:
Hello I'm a newbie in VB .NET and I'd like to accomplish a (I think) very simple task. What I want to do is throw an error message to the user whenever something happens. The main point is...
2
by: William Payne | last post by:
Hello. Consider the following code snippet (pseudo-code). void foo() { /* do stuff */ if fatal error occurs { throw "error message"; }
0
by: Yan | last post by:
Hi. I am having trouble running my aspx code. I created two simple webforms, which i try to run from two different directories one is giving me Compiler Error Message: The compiler failed...
1
by: Jim Davis | last post by:
I've been happily using a custom error handler of the following form for a while now: window.onerror = function(Message, URL, Line) { ... } The current case is an intranet application (support...
1
by: Christof Nordiek | last post by:
Hi, the Service I wrote in C# may fail to start for some reason. I can report that failure to the SMC resp. to the net start command by setting ExitCode to a non zero value and then throw an...
1
by: David Greenberg | last post by:
Hi In my DTS I am updating an Ingres database on a different server. I'm getting the following error immedtiately .... HResult of 0x80040e09 (-2147217911) returned Unexpected error occured. An...
0
by: RaviRajhulk | last post by:
I am trying to execute a batch file from a perl code and its executing fine with the folowing code Code: ( text ) `C:\temp\sample.bat` ,but another problem is occuring.....when there is some...
16
by: njsimha | last post by:
Hi, I have the following XML snippet: <root> <template1> <elem1>1000</elem1> <elem2> <subelem1>65</subelem1>
4
by: zaklost | last post by:
Hello All, I'm really new to this, so sorry ahead of time. Trying to get data to be posted into a table along with other information that's already being put into there. I'm using access...
7
gskoli
by: gskoli | last post by:
Error - working in IE and MOzilla but giving error null or not a object: Guys i am giving you snippet of code , where it is javascript digital clock , It is showing time and working properly but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.