public Exception MultipleNestedTryFinally(ExceptionKind kind)
        {
            try
            {
                try
                {
                    try
                    {
                        try
                        {
                            Throw(kind);
                        }
                        finally
                        {
                            DoNothing();
                        }
                    }
                    finally
                    {
                        DoNothing();
                    }
                }
                finally
                {
                    DoNothing();
                }
            }
            catch (Exception ex)
            {
                return(ex);
            }

            return(null);
        }
        public Exception ThrowAndCatch_ManyCatchBlocks(ExceptionKind kind)
        {
            try
            {
                Throw(kind);
            }
            catch (Exception5 ex)
            {
                return(ex);
            }
            catch (Exception4 ex)
            {
                return(ex);
            }
            catch (Exception3 ex)
            {
                return(ex);
            }
            catch (Exception2 ex)
            {
                return(ex);
            }
            catch (Exception ex)
            {
                return(ex); // actual
            }

            return(null);
        }
        public Exception MultipleNestedTryCatch_LastCatches(ExceptionKind kind)
        {
            try
            {
                try
                {
                    try
                    {
                        try
                        {
                            Throw(kind);
                        }
                        catch (Exception1)
                        {
                            throw;
                        }
                    }
                    catch (Exception2)
                    {
                        throw;
                    }
                }
                catch (Exception3)
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                return(ex);
            }

            return(null);
        }
 private void ThrowRecursive(ExceptionKind kind, int depth)
 {
     if (depth-- == 0)
     {
         Throw(kind);
     }
     else
     {
         ThrowRecursive(kind, depth);
     }
 }
        public Exception CatchAndThrowOtherDeep(ExceptionKind kind)
        {
            try
            {
                Level1ThrowOther(kind);
            }
            catch (Exception ex)
            {
                return(ex);
            }

            return(null);
        }
        public Exception ThrowAndCatchWhen(ExceptionKind kind)
        {
            try
            {
                Throw(kind);
            }
            catch (Exception ex) when(ReturnTrue())
            {
                return(ex);
            }

            return(null);
        }
        public Exception TryAndCatchDeep_CaugtAtTheTop(ExceptionKind kind)
        {
            try
            {
                Level1TryDontCatch(kind);
            }
            catch (Exception ex) // the handler that actualy catches the exception
            {
                return(ex);
            }

            return(null);
        }
        public Exception CatchAndRethrowDeep(ExceptionKind kind)
        {
            try
            {
                Level1Rethrow(kind);
            }
            catch (Exception ex)
            {
                return(ex);
            }

            return(null);
        }
        public Exception ThrowAndCatch(ExceptionKind kind)
        {
            try
            {
                Throw(kind);
            }
            catch (Exception ex)
            {
                return(ex);
            }

            return(null);
        }
        public Exception ThrowAndCatchDeepRecursive(ExceptionKind kind)
        {
            try
            {
                ThrowRecursive(kind, 10);
            }
            catch (Exception ex)
            {
                return(ex);
            }

            return(null);
        }
        public Exception ThrowAndCatchDeep(ExceptionKind kind)
        {
            try
            {
                Level1(kind);
            }
            catch (Exception ex)
            {
                return(ex);
            }

            return(null);
        }
        public Exception TryAndFinallyDeep(ExceptionKind kind)
        {
            try
            {
                Level1Finally(kind);
            }
            catch (Exception ex)
            {
                return(ex);
            }

            return(null);
        }
Example #13
0
        private static string KindToString(ExceptionKind ek)
        {
            switch (ek)
            {
            case ExceptionKind.Inner:
                return("Inner exception");

            case ExceptionKind.LoaderException:
                return("Loader exception");

            default:
                return("Exception");
            }
        }
        public Exception ThrowAndCatchWhenFinally(ExceptionKind kind)
        {
            try
            {
                Throw(kind);
            }
            catch (Exception ex) when(ReturnTrue())
            {
                return(ex);
            }
            finally
            {
                DoNothing();
            }

            return(null);
        }
Example #15
0
        /// <summary>
        /// Formats exception information for bug report
        /// </summary>
        /// <param name="ex">Exception to process</param>
        /// <param name="sb">StringBuilder used for output</param>
        /// <param name="kind">what kind of exception is this</param>
        private static void FormatException(Exception ex, StringBuilder sb, ExceptionKind kind)
        {
            sb.Append("<tr><td>" + KindToString(kind) + ":<td><code>"
                      + ex.GetType().Name + "</code><tr><td>Message:<td><code>"
                      + ex.Message + "</code><tr><td>Call stack:<td><pre>" + ex.StackTrace + "</pre></tr>\r\n");

            if (ex.InnerException != null)
            {
                FormatException(ex.InnerException, sb, ExceptionKind.Inner);
            }
            if (ex is ReflectionTypeLoadException)
            {
                foreach (Exception e in ((ReflectionTypeLoadException)ex).LoaderExceptions)
                {
                    FormatException(e, sb, ExceptionKind.LoaderException);
                }
            }
        }
            /// <summary>
            /// Formats exception information for bug report
            /// </summary>
            /// <param name="ex">Exception to process</param>
            /// <param name="sb">StringBuilder used for output</param>
            /// <param name="kind">what kind of exception is this</param>
            private static void FormatException(Exception ex, StringBuilder sb, ExceptionKind kind)
            {
                sb.AppendFormat("<tr><th>{0}:</th><td>`{1}`</td></tr>\r\n", KindToString(kind), ex.GetType().Name);
                sb.AppendFormat("<tr><th>Message:</th><td>`{0}`</td></tr>\r\n", ex.Message);
                sb.AppendFormat("<tr><th>Call stack:</th><td><pre>{0}</pre></td></tr>\r\n", ex.StackTrace);

                if (ex.InnerException != null)
                {
                    FormatException(ex.InnerException, sb, ExceptionKind.Inner);
                }
                if (ex is ReflectionTypeLoadException)
                {
                    foreach (Exception e in ((ReflectionTypeLoadException)ex).LoaderExceptions)
                    {
                        FormatException(e, sb, ExceptionKind.LoaderException);
                    }
                }
            }
        /// <summary>
        /// Formats exception information for bug report
        /// </summary>
        /// <param name="ex">Exception to process</param>
        /// <param name="sb">StringBuilder used for output</param>
        /// <param name="kind">what kind of exception is thise</param>
        private static void FormatException(Exception ex, StringBuilder sb, ExceptionKind kind)
        {
            sb.Append("<tr><td>" + KindToString(kind) + ":<td><code>"
                + ex.GetType().Name + "</code><tr><td>Message:<td><code>"
                + ex.Message + "</code><tr><td>Call stack:<td><pre>" + ex.StackTrace + "</pre></tr>\r\n");

            if (ex.InnerException != null)
            {
                FormatException(ex.InnerException, sb, ExceptionKind.Inner);
            }
            if (ex is ReflectionTypeLoadException)
            {
                foreach (Exception e in ((ReflectionTypeLoadException)ex).LoaderExceptions)
                {
                    FormatException(e, sb, ExceptionKind.LoaderException);
                }
            }
        }
 private void Throw(ExceptionKind kind)
 {
     if (kind == ExceptionKind.Software)
     {
         throw new Exception();
     }
     else if (kind == ExceptionKind.Hardware)
     {
         _consumer.Consume(AlwaysNull.GetHashCode()); // this is going to throw a NullReferenceException
     }
     else if (kind == ExceptionKind.ReflectionSoftware)
     {
         _throwMethod.Invoke(this, _throwMehtodParameterSoft);
     }
     else if (kind == ExceptionKind.ReflectionHardware)
     {
         _throwMethod.Invoke(this, _throwMehtodParameterHard);
     }
 }
 public AppException(ExceptionKind exceptionKind) : base(exceptionKind.ToString())
     => ExceptionKind = exceptionKind;
Example #20
0
            /// <summary>
            /// Formats exception information for bug report
            /// </summary>
            /// <param name="ex">Exception to process</param>
            /// <param name="sb">StringBuilder used for output</param>
            /// <param name="kind">what kind of exception is this</param>
            private static void FormatException(Exception ex, StringBuilder sb, ExceptionKind kind)
            {
                sb.AppendFormat("<tr><th>{0}:</th><td>`{1}`</td></tr>\r\n", KindToString(kind), ex.GetType().Name);
                sb.AppendFormat("<tr><th>Message:</th><td>`{0}`</td></tr>\r\n", ex.Message);
                sb.AppendFormat("<tr><th>Call stack:</th><td><pre>{0}</pre></td></tr>\r\n", ex.StackTrace);

                if (ex.InnerException != null)
                {
                    FormatException(ex.InnerException, sb, ExceptionKind.Inner);
                }
                if (ex is ReflectionTypeLoadException)
                {
                    foreach (Exception e in ((ReflectionTypeLoadException)ex).LoaderExceptions)
                    {
                        FormatException(e, sb, ExceptionKind.LoaderException);
                    }
                }
            }
Example #21
0
 protected SheaftException(ExceptionKind kind, Exception exception, string error = null, params object[] objs) : base(exception?.Message ?? $"{kind:G}{(error != null ? $":{error:G}":string.Empty)}", exception)
 {
     Kind   = kind;
     Error  = error;
     Params = objs;
 }
 private void Level10Rethrow(ExceptionKind kind)
 {
     try { Throw(kind); } catch (Exception) { throw; }
 }
 private void Level8Finally(ExceptionKind kind)
 {
     try { Level9Finally(kind); } finally { DoNothing(); }
 }
 private void Level10TryDontCatch(ExceptionKind kind)
 {
     try { Throw(kind); } catch (Exception10) { throw; }
 }
 private void Level9TryDontCatch(ExceptionKind kind)
 {
     try { Level10TryDontCatch(kind); } catch (Exception9) { throw; }
 }
 private void Level7TryDontCatch(ExceptionKind kind)
 {
     try { Level8TryDontCatch(kind); } catch (Exception7) { throw; }
 }
 private void Level5TryDontCatch(ExceptionKind kind)
 {
     try { Level6TryDontCatch(kind); } catch (Exception5) { throw; }
 }
 private void Level3TryDontCatch(ExceptionKind kind)
 {
     try { Level4TryDontCatch(kind); } catch (Exception3) { throw; }
 }
 private void Level10ThrowOther(ExceptionKind kind)
 {
     try { Throw(kind); } catch (Exception ex) { throw new Exception("level10", ex); }
 }
 private void Level8ThrowOther(ExceptionKind kind)
 {
     try { Level9ThrowOther(kind); } catch (Exception ex) { throw new Exception("level8", ex); }
 }
 private void Level1TryDontCatch(ExceptionKind kind)
 {
     try { Level2TryDontCatch(kind); } catch (Exception1) { throw; }
 }
 private void Level10Finally(ExceptionKind kind)
 {
     try { Throw(kind); } finally { DoNothing(); }
 }
 private static string KindToString(ExceptionKind ek)
 {
     switch (ek)
     {
         case ExceptionKind.Inner:
             return "Inner exception";
         case ExceptionKind.LoaderException:
             return "Loader exception";
         default:
             return "Exception";
     }
 }
Example #34
0
 /// <summary>
 /// See the comments in recovery.cs for explanation how this work
 /// </summary>
 /// <param name="_exception"></param>
 /// <param name="ek"></param>
 /// <returns></returns>
 public static int handleException(Exception _exception, ExceptionKind ek)
 {
     if (IgnoreErrors || ek == ExceptionKind.Safe)
     {
         Console.WriteLine("EXCEPTION: " + _exception.StackTrace);
         return 2;
     }
     if (ek == ExceptionKind.Critical)
     {
         RecoveryIsFatal = true;
     }
     DebugLog(_exception.Message + " at " + _exception.Source + " info: " + _exception.Data.ToString());
     IsBlocked = true;
     recovery_exception = _exception;
     if (Configuration.Kernel.KernelDump)
     {
         Core.DebugLog("Generating report");
         string dump = "KERNEL DUMP\n\n";
         dump += "Time: " + DateTime.Now.ToString() + "\n";
         dump += "Version: " + Application.ProductVersion + RevisionProvider.GetHash() + "\n";
         dump += "Extensions: " + "\n";
         lock (Extensions)
         {
             foreach (Extension xx in Extensions)
             {
                 dump += "  " + xx.Name + " version: " + xx.Version + " status: " + xx._Status.ToString() + "\n";
             }
         }
         dump += "Exception: " + _exception.Message + "\n";
         dump += "Source: " + _exception.Source + "\n";
         dump += "Status: " + _Status.ToString() + "\n";
         dump += "Stack trace: " + _exception.StackTrace + "\n";
         if (_exception.InnerException != null)
         {
             dump += "Inner: " + _exception.InnerException.ToString() + "\n";
         }
         dump += "Thread name: " + Thread.CurrentThread.Name + "\n";
         dump += "Is kernel: " + (Thread.CurrentThread != _KernelThread).ToString() + "\n";
         dump += "Ring log:\n";
         foreach (string line in RingBuffer)
         {
             dump += line + "\n";
         }
         dump += "That's all folks";
         int current = 0;
         string file = Root + "dump__" + current.ToString();
         while (File.Exists(file))
         {
             current++;
             file = Root + "dump__" + current.ToString();
         }
         File.WriteAllText(file, dump);
     }
     _RecoveryThread = new Thread(Recover);
     _RecoveryThread.Start();
     if (Thread.CurrentThread != _KernelThread)
     {
         DebugLog("Warning, the thread which raised the exception is not a core thread, identifier: " + Thread.CurrentThread.Name);
     }
     while (IsBlocked || RecoveryIsFatal)
     {
         Thread.Sleep(100);
     }
     return 0;
 }