0

I have code like this to show me the StackTrace from an exception I'm getting:

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

...but I cannot see the entire communique from the bowels of the puny confounded contraption (handheld device) due to the real estate constraints; I cannot drag the MessageBox higher - it bumps its head against the top and refuses to make a hole in the roof so that I can see the rest of the story.

So how can I get the MessageBox to split the string into "episodes" that I can cycle through?

My idea (pseudocode) is something like this:

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;
    }
}

...but I reckon somebody "out there" has a better idea or has already solved this...did I reckon right?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    Take a look at / possible duplicate of http://stackoverflow.com/questions/419019/split-list-into-sublists-with-linq – gunr2171 Jun 16 '14 at 17:26
  • 2
    If you use a chain of message boxes, accidental "ok" clicks are around the corner, after which the relevant part disappears. How about rolling your own messagebox with a multiline, read-only textbox and a vertical scroll bar? – C.Evenhuis Jun 16 '14 at 17:42
  • I'm not worried about accidental "ok" clicks; this is just a temporary debugging throwaway bit of code for myself. – B. Clay Shannon-B. Crow Raven Jun 16 '14 at 17:46
  • 2
    You might need it again in the future... You needed it at least once already. – Steve Jun 16 '14 at 18:20
  • 1
    Btw. it might be a better idea to just print out `exception.ToString()` instead of extracting single bits such as `exception.Message` and `exception.StackTrace`. With `.ToString()`, you are getting a full representation of the exception, which might include full details about the the `.InnerException`. If you just print the `.StackTrace`, you'll miss that part of the exception in your debug output. – stakx - no longer contributing Jun 16 '14 at 18:39
  • @stakx: Okay, I updated the answer to reflect that. In my case, it didn't give me any more to go on, but it is cleaner and has no less information, so I'll retain your alternative. – B. Clay Shannon-B. Crow Raven Jun 16 '14 at 18:55

1 Answers1

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
Community
  • 1
  • 1
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862