Showing results for 
Search instead for 
Did you mean: 

PHP API: try/catch for connections

I'm using the PHP API and I'd like to put a try/catch to see if we are not connecting to and I'm not sure of the best place to put it in the code.


Should I put it around this execute?

$response = $controller->executeWithApiResponse($configHandle->getUrl());





Regular Contributor

Hi Don,


That's a fine place for it. You could always go further into the code and modify the "executeWithApiResponse" method or one of its parents to do that kind of error checking at a lower level. I wouldn't. Better instead to keep those additions in your code instead of modifying the SDK.


Just know that if you do catch an exception from that statement, the code will proceed but the "$response" variable will be undefined, so that will cause a couple of more errors to be output. You can either try to trap those or just not worry about them since you've already caught the exception leading to those errors.

All Star