Skip to content

Commit 975db3d

Browse files
committed
Split UnexpectedTypeException for logic and runtime errors
Invalid arguments and options constitute a logic error, so InvalidArgumentTypeException may be used. For runtime errors (e.g. server returned something we didn't expect), UnexpectedValueTypeException may be used.
1 parent 8665a88 commit 975db3d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace MongoDB\Exception;
4+
5+
class InvalidArgumentTypeException extends InvalidArgumentException
6+
{
7+
public function __construct($name, $value, $expectedType)
8+
{
9+
parent::__construct(sprintf('Expected %s to have type "%s" but found "%s"', $name, $expectedType, is_object($value) ? get_class($value) : gettype($value)));
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace MongoDB\Exception;
4+
5+
class UnexpectedValueTypeException extends UnexpectedValueException
6+
{
7+
public function __construct($name, $value, $expectedType)
8+
{
9+
parent::__construct(sprintf('Expected %s to have type "%s" but found "%s"', $name, $expectedType, is_object($value) ? get_class($value) : gettype($value)));
10+
}
11+
}

0 commit comments

Comments
 (0)