Issue Bug Closed

#66411New locking API exceptions too generic

Mathias Brodala 04/14/15, 09:57 updated 10/19/17, 21:15

Description

The new locking API currently only uses RuntimeException to hint at errors during lock acquisition.

While this already has the disadvantage of catching other RuntimeExceptions the issue becomes rather clear with the non-blocking example:

try {
  $result = $locker->acquire(LockingStrategyInterface::LOCK_CAPABILITY_SHARED | LockingStrategyInterface::LOCK_CAPABILITY_NOBLOCK);
catch (\RuntimeException $e) {
  if ($e->getCode() === 1428700748) {
    // some process owns the lock, let's do something else meanwhile
  }
}

This requires knowing about this special case and knowing the magic number here. A dedicated exception would make this clearer.

Reviews 1