发布网友 发布时间:2022-04-23 13:09
共1个回答
热心网友 时间:2022-04-08 02:24
PHP操作MongoDB的 exception handling没有什么特别的地方,和其他的场景一样,使用try catch来处理。
PHP MongDB client包含了一些exeception的类:
MongoDB\Driver\Exception\AuthenticationException
MongoDB\Driver\Exception\BulkWriteException
MongoDB\Driver\Exception\ConnectionException
MongoDB\Driver\Exception\ConnectionTimeoutException
MongoDB\Driver\Exception\Exception
MongoDB\Driver\Exception\ExecutionTimeoutException
MongoDB\Driver\Exception\InvalidArgumentException
MongoDB\Driver\Exception\LogicException
MongoDB\Driver\Exception\RuntimeException
MongoDB\Driver\Exception\SSLConnectionException
MongoDB\Driver\Exception\UnexpectedValueException
MongoDB\Driver\Exception\WriteException
但是您估计为了简化,只会统一处理MongoDB\Exception\Exception。
正如一楼的朋友所言,可以做一些类来封装此类操作使得事情简洁一些。