Replace assert with check and add exception.
Verify cacert existence before using it.

Closes #3362.
Merge remote-tracking branch 'ivan/bug/3362_check-if-cacert-exists' into develop