semaphore releasing if exception occurs