我需要将所有方法层次结构的堆栈跟踪转换为异常,但它显示为firstlevel方法 [英] I need stack trace with all hierarchy of method into exception but it shows upto firstlevel method

查看:65
本文介绍了我需要将所有方法层次结构的堆栈跟踪转换为异常,但它显示为firstlevel方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }

       private void Form1_Load(object sender, EventArgs e)
       {
           try
           {
              Parallel.Invoke(
                  () => this.BeginInvoke((Action)delegate
                  {
                      FirstLevel();
                  })
                  );
           }
           catch (Exception ex)
           {
               throw;
           }
       }

       private void FirstLevel()
       {
           try
           {
                   SecondLevel();

           }
           catch (Exception ex)
           {
               throw;
           }
       }

       private void SecondLevel()
       {
           try
           {
               ThirdLevel();
           }
           catch (Exception ex)
           {
               throw;
           }
       }

       private void ThirdLevel()
       {
           try
           {
               throw new DivideByZeroException();
           }
           catch (Exception ex)
           {
               throw;
           }
       }

       private void button1_Click(object sender, EventArgs e)
       {
           try
           {
               FirstLevel();
           }
           catch (Exception ex)
           {
               throw;
           }
       }
   }





我尝试过:





What I have tried:

I have desktop application in which i have created the one form into which i have called FirstLevel method into parallel threading then firstlevel() method call secondlevel method,secontlevel method call thridlevel method and third level method have exception all method have try catch with throw but whenever exception occured the stack trace got the exception upto Firstlevel method it does not capture the Form1_Load method. ineed the all hierarchy of method into exception.



如果我删除了线程FROM Form1_load方法,那么它获得了方法的层次结构异常但是如果我使用线程则它没有t发生了form1_Load方法


If i remove the threading FROM Form1_load method then it got the hierarchy exception of method but if i use the threading the it doesn't occurred the form1_Load method

推荐答案

这是因为它不存在:每个线程都有自己的,独立的堆栈(或者它们会相互干扰)和堆栈trace is - 正确 - 只能返回抛出异常的特定线程的堆栈信息。



实际上只要你有足够的内核Form1_Load方法可能会在抛出异常之前完成原始线程(UI线程)堆栈!
That's because it doesn't exist: each thread gets its own, separate stack (or they would interfere with each other) and the stack trace is - rightly - only able to return information for the stack for the specific thread that threw the exception.

In fact as long as you have enough cores the Form1_Load method is probably going to have been finished and the original thread (the UI thread) stack cleared before the exception is thrown!


这篇关于我需要将所有方法层次结构的堆栈跟踪转换为异常,但它显示为firstlevel方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆