Fix throw exception on emit file

Fix issue #852
I'm not really clear on what the additional text in this comment specifies. Do you mean "or when called from 'getSemanticDiagnostics'"?