Example #1
0
        public static void HandleFatalException(Exception ex)
        {
            // We can't use the Console class here (because it is
            // defined in a library that depends on this one).
            // Instead, we'll use IO primitives, which have the
            // added advantage of being leaner.
            var errorMessage = Marshal.StringToHGlobalAnsi(
                "error: a fatal exception was thrown." + NewLine +
                "Exception message: " + ex.Message + NewLine);

            IOPrimitives.WriteCStringToFile(
                (byte *)errorMessage.ToPointer(),
                IOPrimitives.StandardErrorFile);

            Marshal.FreeHGlobal(errorMessage);
        }