28 January 2008

Be nice, would ya?

Was doing a SQL-based "blanket" delete of a client and all its related tables. That required me to loop through all the tables involving the ClientId and deleting them. Sure I can use CASCADING, but for more control (am I a control freak?), I wanted to manually walk through them.

I used the DataGridView to display all the data and used the UserDeletingRow event to handle the Delete key. Well, at the end of the event, the application bombs from the exe (not the debugger) for "no reason" spitting out the below:

************** Exception Text **************
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Windows.Forms.DataGridViewRowCollection.SharedRow(Int32 rowIndex)
at System.Windows.Forms.DataGridViewRowCollection.get_Item(Int32 index)
at System.Windows.Forms.DataGridView.ProcessDeleteKey(Keys keyData)
at System.Windows.Forms.DataGridView.ProcessDataGridViewKey(KeyEventArgs e)
at System.Windows.Forms.DataGridView.OnKeyDown(KeyEventArgs e)
at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.DataGridView.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Well, everything has a reason, and I'm sure this does too, but I want to handle the foresaken error and make nice to the users. The error doesn't affect the application at all if I press 'Continue' at the Debug dialog so...

Came across several forums saying there might be bugs in the DataGridView since MS developers might had let some things "slip". Cannot say for sure.

Then was looking for some code to handle these kind of errors if it something that cannot be handled within the class. The last entry in the error above "...Callback(..." gave me a clue that it's an asynchronous event or a threading issue.

So created an event handler in the entry point of the application:


[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
...
}

static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs t)
{
Exception e = (Exception)t.Exception;
System.Diagnostics.EventLog.WriteEntry(
"AactsThreadExceptionHandler", e.Message, System.Diagnostics.EventLogEntryType.Error);
}
or

http://support.microsoft.com/Default.aspx?kbid=836674

Hope that's instructional enough for anyone to stumble across here!

Thought those days are gone?

I'm writing .NET code in C# for an app. During testing, my client reported a serious error -- huh, how'd you get that error? Tried replicating it in Visual Studio... no dice, then using the compiled exe, I was able to duplicate it, but the error didn't make sense... it kept throwing some nonsensical blubbering:

EventType clr20r3, P1 appnamehere.exe, P2 3.0.0.0, P3 45f6dbdb, P4 appnamehere, P5 3.0.0.0, P6 45f6dbdb, P7 18, P8 0, P9 pszqoadhx1u5zahbhohghldgiy4qixhx, P10 NIL.

Say what? Trying to find a best way to debug this... googled 'clr20r3' and came across this blog entry:

http://www.blackteaconsulting.com/journal/?p=116

Simply add the following in your project's entry point:


[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

...
}

static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
System.Diagnostics.EventLog.WriteEntry(
"AppErrorHandler", e.Message, System.Diagnostics.EventLogEntryType.Error);
}

Bingo! From looking at the Event Viewer, it was now clearly pointing to an non-existent database -- whoops, the database connection string was being inadvertently changed. Easy fix.

Thanks Wall Street guy!

Back when I was coding in VB6, there's runtime errors that didn't happen in the debug environment -- but doesn't say why or where in the application the error was occuring. Had to revert to some sleuthing and outputting strings -- painstaking work!

Now, excuse me while I see about this other problem... I'll report back.

13 January 2008

A new Seinfeld episode?

Rumors has it that there'll be a new Seinfeld episode. Plot summary: Kramer writes a new coffee table cookbook (that George suggested) geared towards kids that Elaine publishes. Sue Ellen Mischke (the lady from the Indian wedding) also had published a eerie similar book also suggested to her by George in passing. Sue Ellen sues Kramer. Seinfeld gets sued for defamation by using Sue Ellen's name in one of his comedy acts. Poor Elaine is in the middle of it all.

Oh, it's not a new episode...
http://www.cnn.com/2008/SHOWBIZ/books/01/08/people.seinfeld.ap/index.html

That is a bonafide episode!

09 January 2008

Extreme Ojo messages

Some of us has taken to the extremes with our Ojos. Since Ojos aren't required to be connected when you record a signed or spoken message there's a certain flexibility on what you can do:

One friend took his Ojo out for a ride in his car with an power adapter, he was able to record a signed message. (may have broken several laws doing that)

Using that as an inspiration -- what Ojo message would take the cake so to speak?
1. Skydiving with your Ojo along with a battery pack?
2. Record a message upside down?
3. Going to Italy and recording a message with Pisa as your backdrop?

Ideas? No ideas too idiotic...