2

I'm using \lithium\data\source\MongoDB::update() to do an upsert in safe mode. On some updates, there is an expected MongoCursorException due to a duplicate key being passed. The try/catch below does not catch the error, and it bubbles back up to an ErrorHandler I have attached to Dispatcher::run().

try {
    $result = Items::update($record, $conditions, array('upsert' => true, 'safe'   => true));
} catch (MongoCursorException $e) {
    $result = false;
} catch (Exception $e) {
    $result = false;
}
Eric C
  • 971
  • 6
  • 14

1 Answers1

5

You need to add use statements to the top of your file, or put a backslash in front of the exception class names to indicate they are from the global scope and not your namespace. I prefer the use statements at the top of the class.

use MongoCursorException;
use Exception;
rmarscher
  • 5,596
  • 2
  • 28
  • 30