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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.