Fix string concatenation to os.path.join and add exception case
Summary:
Backport of core PR11291
https://github.com/bitcoin/bitcoin/pull/11291/files
Test Plan:
make check
Reviewers: #bitcoin_abc, deadalnix
Reviewed By: #bitcoin_abc, deadalnix
Differential Revision: https://reviews.bitcoinabc.org/D3427