3.2 - Handling errors
The principle
try {
// Execution (stops and goes in the catch block if an error occurs)
}
catch {
// Error handling (tries to catch the error or the error display)
} Example
try {
// creating web service access
$webService = new PrestaShopWebservice( 'http://maboutique.com/', 'ZR92FNY5UFRERNI3O9Z5QDHWKTP3YIIT', false );
// call to retrieve all clients
$xml = $webService->get( array( 'resource' => 'customers' ) );
}
catch ( PrestaShopWebserviceException $ex ) {
$trace = $ex->getTrace(); // Retrieve all information on the error
$errorCode = $trace[ 0 ][ 'args' ][ 0 ]; // Retrieve the error code
if ( $errorCode == 401 )
echo 'Bad auth key';
else
echo 'Other error : <br />' . $ex->getMessage(); // Shows a message related to the error
}Last updated
Was this helpful?
