Ejemplo n.º 1
0
        // Set a particular error number in the program's error object.
        private static void SetErrorNumber(int number)
        {
            ErrObject error = Information.Err();

            error.Clear();
            error.Number = number;
        }
Ejemplo n.º 2
0
        // Throw an exception by number.
        public static void ThrowException(int hr)
        {
            Exception exception =
                ErrObject.CreateExceptionFromNumber(hr, null);

            SetErrorNumber(hr);
            throw exception;
        }
Ejemplo n.º 3
0
        // Create a new project error.
        public static Exception CreateProjectError(int hr)
        {
            ClearProjectError();
            hr = ErrObject.HResultToNumber(hr);
            Exception e = ErrObject.CreateExceptionFromNumber(hr, null);

            Information.Err().Number = hr;
            return(e);
        }
Ejemplo n.º 4
0
        /// <summary>Performs the work for the <see langword="Raise" /> method of the <see langword="Err" /> object. A helper method.</summary>
        /// <param name="hr">An integer value that identifies the nature of the error. Visual Basic errors are in the range 0–65535; the range 0–512 is reserved for system errors; the range 513–65535 is available for user-defined errors.</param>
        /// <returns>An <see cref="T:System.Exception" /> object.</returns>
        public static Exception CreateProjectError(int hr)
        {
            ErrObject errObject = Information.Err();

            errObject.Clear();
            int num = errObject.MapErrorNumber(hr);

            return(errObject.CreateException(hr, Utils.GetResourceString((vbErrors)num)));
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            ErrObject err = Information.Err();

            // Definitions
            const int PART1_LENGTH  = 5;
            string    sPart1        = "Some value";
            int       vbObjectError = 123;
            double    d;

            if (sPart1.Length != PART1_LENGTH)
            {
                err.Raise(vbObjectError, null, "Part 1 must be " + PART1_LENGTH);
            }
            else if (double.TryParse(sPart1, out d))
            {
                err.Raise(vbObjectError, null, "Part 1 must be numeric");
            }
        }
Ejemplo n.º 6
0
 // Throw a particular exception, after setting the error number.
 private static void ThrowExceptionInternal(Exception exception)
 {
     SetErrorNumber(ErrObject.GetNumberForException(exception));
     throw exception;
 }