Exception handling when Piwik server is down

I need to find a way to detect and correctly handle the situation when Piwik server is down.
Right now when there is something wrong with Piwik server it causes whole application to stop working.
I have my piwik host ip specified in config file and let’s pretend the server is down or someone changes the config file.
Is there a way to make some custom error handling so that when Piwik server is down or the app can’t connect to Piwik it won’t make the whole app stop working?