Jump to content

Exception question


makeshift_theory

Recommended Posts

Okay, I have a question.  I just started using Exceptions in my code and for some reason this method cannot find the catch statement.  Here is the code:
[code] protected function export_mysql_to_excel()
{
include_once "commands.class.php";
include_once "../../config.php";

$db = new Commands;
$db->set_server($config['host'],$config['user'],$config['pass']);
$db->connect();
$db->select_db($config['db']);
$db->do_query("SELECT * FROM {$this->table}");
$count = mysql_num_fields($db->queryr); // get number of rows
for($i=0;$i < $count;$i++)
{
$headers .= mysql_field_name($db->queryr, $i) . "\t";
}
while($r = mysql_fetch_row($db->queryr))
{
$line = ''; // Reset our line
foreach($r as $value)
{
if(!isset($r) || $r == '')
$value = "\t";
else
{
$value = str_replace('"','""', $value);
$value = $value .  "\t";
}
$line .= $value;
}
$data .= trim($line) . "\n";
}
$data = str_replace("\r","",$data); // Replace \r in the variabes with a blank

if(isset($headers) && isset($data))
{
$this->headerrow = $headers; // Set our HeaderRow
$this->data = $data; // Set our Data in Class
}
else
throw new Exception('Could not parse data correctly.');

try{
if(isset($headers) && isset($data))
{
$this->headerrow = $headers; // Set our HeaderRow
$this->data = $data; // Set our Data in Class
}
}
catch(Exception $e){
  echo 'Error :'.$e->getMessage().'<br />';
  echo 'Code :'.$e->getCode().'<br />';
  echo 'File :'.$e->getFile().'<br />';
  echo 'Line :'.$e->getLine().'<br />';
  exit();
}
}
[/code]

It gives off the "cannot find catch" error, any aid please?
Link to comment
https://forums.phpfreaks.com/topic/32723-exception-question/
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.