Error handling is a mix of return codes, exception and setting an error in/out variable. Rework this to be exception-only where possible.