Jump to content

unexpected catch block


rubing

Recommended Posts

I thought someone could explain why the following code doesn't work.  First, I make a call to a class method.  I want to catch any exceptions that are thrown by this method.  I thought the exceptions thrown in the class would bubble up to script level??  I tried putting a try block around the call to my class method, but this just resulted in the underlying class exception not being caught. 

 

$grab->request_post_info($karma);

catch (Exception $e) 
  { 
$query="INSERT INTO mp3 (sutrasite) VALUES ('$sutra')";
$conn->query($query);
exit;
  }

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/108130-unexpected-catch-block/
Share on other sites

<?php
try
{
    $grab->request_post_info($karma);
}
catch (Exception $e) 
{ 
    $query="INSERT INTO mp3 (sutrasite) VALUES ('$sutra')";
    $conn->query($query);
}
?>

 

That doesn't work?

 

edit - Actually you'll want to catch any exceptions in the $grab object class, not here.

Nope.  When I do that I get the following error

Fatal error: Uncaught exception 'Exception' with message 'my error message' in /path/to/myclass.inc:96 Stack trace: #0 /path/to/my/script.php(45): class_name->get_mp3(NULL) #1 {main} thrown in /path/to/myclass.inc on line 96

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.