Do not try to store the build graph if the underlying file is not writable.

The checks were actually there, but nobody looked at the return value.
Use exceptions instead.

Task-number: QBS-299
Change-Id: I0a48bcb6ea89962804d1d4fd488455f077dcfc4c
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>