Convert to terser form of exception throwing and fix compilation in BSONEncoder