NumPhp raises an
InvalidArgumentException
when something goes wrong
with a method call. A good practice is to catch them.
use SciPhp\NumPhp as np;
try
{
$m = np::ar([1, 2, 3])->log(-1);
}
catch(\InvalidArgumentException $e)
{
echo "{$e->getMessage()}\n";
exit(1);
}
The above example will output:
Expected a value greater than 0. Got: -1
NdArray raises an
SciPhp\Exception\InvalidAttributeException
when a call is made for an unexisting attribute.
use SciPhp\NumPhp as np;
use SciPhp\Exception\InvalidAttributeException;
try
{
$m = np::ar([1, 2, 3])->notExistingAttribute;
}
catch(InvalidAttributeException $e)
{
echo "{$e->getMessage()}\n";
exit(1);
}
The above example will output:
Attribute "notExistingAttribute" is not defined.