// Info: Map and Throw a JavascriptError(Debug) containing restricted error information, if available // Parameters: scriptContext - the script context // hr - HRESULT of the error to be thrown void __declspec(noreturn) JavascriptErrorDebug::MapAndThrowErrorWithInfo(ScriptContext* scriptContext, HRESULT hr) { // Initialize error type to kjstWinRTError if WinRT is enabled, or to kjstError otherwise. #ifdef ENABLE_PROJECTION ErrorTypeEnum errorType = scriptContext->GetConfig()->IsWinRTEnabled() ? kjstWinRTError : kjstError; #else ErrorTypeEnum errorType = kjstError; #endif // Get error type if hr is a runtime error. GetErrorTypeFromNumber(hr, &errorType); EXCEPINFO excepinfo; EXCEPINFO baseline; memset(&baseline, 0, sizeof(baseline)); RestrictedErrorStrings roerrstr; IErrorInfo * perrinfo = nullptr; HRESULT result = GetExcepAndErrorInfo(scriptContext, hr, &excepinfo, &roerrstr, &perrinfo); // If there is WinRT specific information for this error, throw an error including it if (NOERROR == result) { MapAndThrowError(scriptContext, hr, errorType, &excepinfo, perrinfo, &roerrstr, true); } // If there is no restricted info, but unrestricted exception info was obtained, // throw an error with the exception info only else if(memcmp(&excepinfo, &baseline, sizeof(baseline)) != 0) { Assert(!perrinfo); MapAndThrowError(scriptContext, hr, errorType, &excepinfo, nullptr, nullptr, true); } // If no specialized info was obtained, throw an error by HRESULT and type only. else { MapAndThrowError(scriptContext, hr, errorType, nullptr, nullptr, nullptr, true); } }
void __declspec(noreturn) JavascriptError::MapAndThrowError(ScriptContext* scriptContext, HRESULT hr, ErrorTypeEnum errorType, EXCEPINFO* pei, IErrorInfo * perrinfo, RestrictedErrorStrings * proerrstr, bool useErrInfoDescription) { JavascriptError* pError = MapError(scriptContext, errorType, perrinfo, proerrstr); MapAndThrowError(scriptContext, pError, hr, pei, useErrInfoDescription); }