ThrowSavedException() public method

If an exception was generated during a callback throw it.
public ThrowSavedException ( ) : void
return void
Ejemplo n.º 1
0
        public void VerifyStatusCallbackWrapperConvertsArguments()
        {
            var wrapper = new StatusCallbackWrapper(
                (session, snp, snt, obj) =>
                {
                    Assert.IsInstanceOfType(obj, typeof(JET_SNPROG));
                    var snprog = obj as JET_SNPROG;
                    Assert.AreEqual(this.sesid, session);
                    Assert.AreEqual(JET_SNP.Restore, snp);
                    Assert.AreEqual(JET_SNT.Progress, snt);
                    Assert.IsNotNull(snprog);
                    Assert.AreEqual(1, snprog.cunitDone);
                    Assert.AreEqual(100, snprog.cunitTotal);
                    return JET_err.Success;
                });

            var native = new NATIVE_SNPROG
            {
                cbStruct = checked((uint)NATIVE_SNPROG.Size),
                cunitDone = 1,
                cunitTotal = 100,
            };

            unsafe
            {
                wrapper.NativeCallback(
                    this.sesid.Value,
                    (uint)JET_SNP.Restore,
                    (uint)JET_SNT.Progress,
                    new IntPtr(&native));
            }

            wrapper.ThrowSavedException();
        }
Ejemplo n.º 2
0
        public void VerifyStatusCallbackWrapperCatchesExceptions()
        {
            var wrapper = new StatusCallbackWrapper(
                (session, snp, snt, snprog) =>
                {
                    throw new ArgumentException();
                });

            Assert.AreEqual(JET_err.CallbackFailed, wrapper.NativeCallback(this.sesid.Value, 0, 0, IntPtr.Zero));

            try
            {
                wrapper.ThrowSavedException();
                Assert.Fail("Expected an ArgumentException to be thrown");
            }
            catch (ArgumentException)
            {
                // expected
            }
        }
Ejemplo n.º 3
0
        public void VerifyStatusCallbackWrapperCatchesThreadAbort()
        {
            var wrapper = new StatusCallbackWrapper(
                (session, snp, snt, snprog) =>
                {
                    Thread.CurrentThread.Abort();
                    return JET_err.Success;
                });

            Assert.AreEqual(JET_err.CallbackFailed, wrapper.NativeCallback(this.sesid.Value, 0, 0, IntPtr.Zero));

            try
            {
                wrapper.ThrowSavedException();
                Assert.Fail("Expected a ThreadAbortException to be thrown");
            }
            catch (ThreadAbortException)
            {
                // expected
                Thread.ResetAbort();
            }
        }