Exemple #1
0
        private void ReportErrorAndExitRaw(string message, ChessExitCode code, bool genRepro, bool fromExitCallback, Exception ex)
        {
            DiagnoseInstrumentedUninstrumented();

            MErrorInfo errorInfo = ex == null ? null : new MErrorInfo(ex);

            // It's only safe to write to the results printer if we aren't in the exit callback
            if (!fromExitCallback)
            {
                // TODO: action? This var will always have the value of String.Empty.
                var action = "";
                if (message != "")
                {
                    MChessChess.ReportError(message, action, errorInfo);
                }
                else if (code != 0)
                {
                    // we have an error code but no message.
                    var newMessage = new ChessResult(code).ToString();
                    MChessChess.ReportError(newMessage, action, errorInfo);
                }

                MChessChess.ReportFinalStatistics((int)code);
            }

            if (genRepro)
            {
                // must call after all ReportWarning/ReportError calls
                MChessChess.Done(!fromExitCallback);
            }
            else
            {
                // Note: The MChessChess.Done already implicitly calls CloseResults, so
                // we only need to explicitly call it otherwise.
                MChessChess.CloseResults();
            }

            // Invariant: this should be the only exit in the engine!!!
            Environment.Exit((int)code);
        }