Jump to content

[SOLVED] throw new Exception... trouble


unkwntech

Recommended Posts

I have a block of code that looks like this:

function sendResponseCode($code)
{
	error_reporting(0);
	switch ($code)
	 {
                ...SNIP...
	 	default:
	 		throw new Exception('Response Code Not Implemented', '1');  //<-- LINE 11
	 		break;
	 }
	die();
}
...SNIP...
if(!DEFINED(constName))
{
	try
	 {
	sendResponseCode(404);
	 }
	catch(Exception $e)
	 {
		echo $e->getMessage() . ' on line: ' . $e->getLine() . ' of file ' . $e->getFile();
	 }
}

when I run it I am getting the following:

Parse error: parse error, unexpected T_NEW in ...SNIP... on line 11
Link to comment
https://forums.phpfreaks.com/topic/134334-solved-throw-new-exception-trouble/
Share on other sites

function sendResponseCode($code)
{
	error_reporting(0);
	switch ($code)
	 {
                ...SNIP...
	 	case 404:
	 		header('HTTP/1.1 404 Not Found\r\n');
	 		break;
	 	default:
	 		throw new Exception('Response Code Not Implemented', '1');
	 		break;
	 }
	die();
}
...SNIP...
if(!DEFINED(constName))
{
	try
	 {
	sendResponseCode(404);
	 }
	catch(Exception $e)
	 {
		echo $e->getMessage() . ' on line: ' . $e->getLine() . ' of file ' . $e->getFile();
	 }
}

I'm gonna' beat my head against the desk for a while now.... the server I was testing on hadn't been updated for whatever reason to PHP5 so it was still running 4.4.0.

So I'll change the question is there a way to accomplish this in 4?

 

 

Note To Self: Check the versions don't rely on what 'they' tell you.    :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.