Add a try catch block

This function might also be called before ownCloud is setup which results in a PHP fatal error. We therefore should gracefully catch errors in there.
Merge pull request #11625 from owncloud/fix-setup-due-to-some-race-condition

Add a try catch block