Jump to content

[SOLVED] Throwing exceptions not working.


DjMikeS

Recommended Posts

Hi all,

 

I have this code to display a news item. As the news item is set in the url, users can change it to whatever the want resulting in an error because that news item may not exist.

 

I'm trying to catch this error but for some reason it's not thrown. Can anyone help?

 

Here's the code:

<?php
$cntBuffer = new Databuffer();

try {
if (isset($_GET['item'])) {
	$newsId = mysql_real_escape_string($_GET['item']);
	$qryNews = "SELECT * FROM news WHERE id = $newsId";

	if (!$rsltNews = mysql_query($qryNews)) {
		Throw new Exception("error");
	}	
	$arrNews = mysql_fetch_array($rsltNews);
	echo $arrNews[1];
}
}
catch (Exception $e) {
$strError = $e->GetMessage();
echo "There is no such news item.<br /><i>$strError</i>";
}

$cntBody = $cntBuffer->close();
?>

Link to comment
https://forums.phpfreaks.com/topic/126874-solved-throwing-exceptions-not-working/
Share on other sites

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.