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.

@butonic @PVince81 As discussed.

@karlitschek Regression due to a race condition - I'll backport this to stable7 because the concerning commit is in there since today and breaks the setup.