Exceptions

Invalid argument exception

NumPhp raises an InvalidArgumentExceptionwhen something goes wrong with a method call. A good practice is to catch them.

use SciPhp\NumPhp as np;

try
{
  
$m np::ar([123])->log(-1);
}
catch(\
InvalidArgumentException $e)
{
  echo 
"{$e->getMessage()}\n";

  exit(
1);
}

The above example will output:

Expected a value greater than 0. Got: -1

Invalid attribute exception

NdArray raises an SciPhp\Exception\InvalidAttributeExceptionwhen a call is made for an unexisting attribute.

use SciPhp\NumPhp as np;
use 
SciPhp\Exception\InvalidAttributeException;

try
{
  
$m np::ar([123])->notExistingAttribute;
}
catch(
InvalidAttributeException $e)
{
  echo 
"{$e->getMessage()}\n";

  exit(
1);
}

The above example will output:

Attribute "notExistingAttribute" is not defined.