move error catching out of Document, cleaner error handling; show os errno in a consistent way