0

我有这样的代码来向我展示我收到的异常中的 StackTrace:

catch (Exception x)
{
    MessageBox.Show(string.Format("Booboo ({0}) in buttonGetDeviceLangVal_Click(). StackTrace == {1}",
        x.Message, x.StackTrace));
}

...但是由于房地产的限制,我无法从这个小小的令人困惑的装置(手持设备)的内部看到整个公报;我无法将 MessageBox 拖得更高——它的头撞到了顶部,并且拒绝在屋顶上打一个洞,这样我就可以看到故事的其余部分。

那么如何让 MessageBox 将字符串拆分为可以循环播放的“情节”?

我的想法(伪代码)是这样的:

catch (Exception x)
{
    const int MAX_CHARS_TO_SHOW = 314;
    string exmsg = string.Format("Booboo ({0}) in 
        buttonGetDeviceLangVal_Click(). StackTrace == {1}",
        x.Message, x.StackTrace);
    int msglen = exmsg.Len;
    int charsDisplayed = 0;
    while (charsDisplayed < msglen) do
    {
        string exmsgepisode = String.Copy(exmsg, charsDisplayed, MAX_CHARS_TO_SHOW);
        MessageBox.Show(exmsgepisode);
        charsDisplayed += charsDisplayed;
    }
}

...但我认为“外面”有人有更好的主意或已经解决了这个问题...我认为对吗?

4

1 回答 1

0

This works:

catch (Exception x)
{
    const int MAX_CHARS_TO_SHOW = 314;
    string exmsg = string.Format("Boo-boo in buttonGetDeviceLangVal_Click(): == {0}", x);
    int msglen = exmsg.Length;
    int charsDisplayed = 0;
    while (charsDisplayed < msglen)
    {
        int CharsToGrab = MAX_CHARS_TO_SHOW;
        int CharsLeft = msglen - charsDisplayed;
        if (CharsLeft < MAX_CHARS_TO_SHOW) CharsToGrab = CharsLeft;
        string msgepisode = exmsg.Substring(charsDisplayed, CharsToGrab);
        int episodeLen = msgepisode.Length;
        MessageBox.Show(msgepisode);
        charsDisplayed = charsDisplayed + episodeLen;
    }
}

Unfortunately, the resulting dual episodic MessageBox showing didn't help me much with the underlying problem. It just tells me (in a nutshell):

Control-OnClick
Button-Onclick
ButtonBase-WinProc
Forms.Ctrl_InternalWinProc
Microsoft.AGL.Forms.EVL_EnterMainLoop
ApplicationRun
于 2014-06-16T18:33:51.170 回答