Page 1 of 1

Unhandled exception

Posted: Fri Mar 07, 2008 4:08 pm
by 8739068
I ran into a case where the TeeChart control was throwing an exception and it was not getting handled.

This exception was causing my application to crash and until I looked into my Windows Event Viewer under Application Logs I could not figure out what was causing the problem.

Because we have the source code I was able to load up the TeeChart for .NET V3 source and find the offending line of code.

I am not clear how to reproduce the exception in a simple example, but below is what I found

When inspecting the Call to CanvasGDIplus.public override void Ellipse(int x1, int y1, int x2, int y2) , the following was passed in

x1 = 2147483646
y1 = 2147483646
x2 = -2147483646
y2 = -2147483646

Code: Select all

public override void Ellipse(int x1, int y1, int x2, int y2) 
{
    Rectangle r=new System.Drawing.Rectangle(x1,y1,x2-x1,y2-y1);

    if (Brush.visible)
    if (Brush.GradientVisible)   
        g.FillEllipse(Brush.Gradient.DrawingBrush(r),r);
    else
        g.FillEllipse(Brush.DrawingBrush,r);  <- Exception "Overflow Error"

    if (Pen.bVisible)
        g.DrawEllipse(Pen.DrawingPen,r);
}
To fix the unhandled exception I added a catch block to the try block within Steema.TeeChart.TChart.Draw(Graphics g) method. The catch block does nothing, but it does prevent an unhandled exception. I would like someone to comment on my solution.

The details of the exception found in the Application Event Viewer were:

Event Type: Information
Event Source: TCCUnhandledException
Event Category: None
Event ID: 0
Date: 3/7/2008
Time: 1:20:55 AM
User: N/A
Computer: TCCJONES
Description:
General Exception in Application with the following information:

Overflow error.

Stack Trace:
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.FillEllipse(Brush brush, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Drawing.Graphics.FillEllipse(Brush brush, Rectangle rect)
at Steema.TeeChart.Drawing.Graphics3DGdiPlus.Ellipse(Int32 x1, Int32 y1, Int32 x2, Int32 y2) in C:\TCC\Development\3rd Party\Source\TeeChartNetV3\Sources\TeeChart\Drawing\CanvasGDIplus.cs:line 760
at Steema.TeeChart.Styles.SeriesPointer.Draw(Graphics3D g, Boolean is3D, Int32 px, Int32 py, Int32 tmpHoriz, Int32 tmpVert, Color colorValue, PointerStyles aStyle) in C:\TCC\Development\3rd Party\Source\TeeChartNetV3\Sources\TeeChart\Styles\Custom.cs:line 650
at Steema.TeeChart.Styles.SeriesPointer.Draw(Int32 px, Int32 py, Color colorValue, PointerStyles aStyle) in C:\TCC\Development\3rd Party\Source\TeeChartNetV3\Sources\TeeChart\Styles\Custom.cs:line 730
at Steema.TeeChart.Styles.CustomPoint.DrawPointer(Int32 aX, Int32 aY, Color aColor, Int32 valueIndex) in C:\TCC\Development\3rd Party\Source\TeeChartNetV3\Sources\TeeChart\Styles\Custom.cs:line 1215
at Steema.TeeChart.Styles.CustomPoint.DrawValue(Int32 valueIndex) in C:\TCC\Development\3rd Party\Source\TeeChartNetV3\Sources\TeeChart\Styles\Custom.cs:line 1345
at Steema.TeeChart.Styles.Series.Draw() in C:\TCC\Development\3rd Party\Source\TeeChartNetV3\Sources\TeeChart\Series.cs:line 3055
at Steema.TeeChart.Styles.Series.DrawSeries() in C:\TCC\Development\3rd Party\Source\TeeChartNetV3\Sources\TeeChart\Series.cs:line 3131
at Steema.TeeChart.Chart.InternalDraw(Graphics g, Boolean noTools) in C:\TCC\Development\3rd Party\Source\TeeChartNetV3\Sources\TeeChart\Chart.cs:line 803
at Steema.TeeChart.Chart.InternalDraw(Graphics g) in C:\TCC\Development\3rd Party\Source\TeeChartNetV3\Sources\TeeChart\Chart.cs:line 685
at Steema.TeeChart.TChart.Draw(Graphics g) in C:\TCC\Development\3rd Party\Source\TeeChartNetV3\Sources\TeeChart\TeeChart.cs:line 565
at Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe) in C:\TCC\Development\3rd Party\Source\TeeChartNetV3\Sources\TeeChart\TeeChart.cs:line 605
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TCPSM.Program.Main() in C:\TCC\Development\Client\Source\TCPSM2\Program.cs:line 119

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Posted: Tue Mar 11, 2008 11:38 am
by narcis
Hi Mike,

The values are Int32.MaxValue and Int32.MinValue. Could you please check that the values you pass to the method are below these max and min values?

Thanks in advance.

Unhandled Exception support thread continued

Posted: Tue Mar 11, 2008 3:09 pm
by 8739068
Accidentally started new topic. I should have pressed the Reply button. Here is a link to the continuation of this topic


http://www.teechart.net/support/viewtop ... 9381#29381

Estimate when this could be addressed

Posted: Tue Dec 09, 2008 8:46 pm
by 8739068
I continually having to modify the source code to add a catch to a try block. This is an easy fix and will prevent the exception from crashing applications.

Could the method in TeeChart.cs have the try catch statement added as shown below?

Code: Select all

        public virtual void Draw(Graphics g)
        {

            bool old = chart.AutoRepaint;
            chart.AutoRepaint = false;
            chart.Graphics3D.oldRegion = new Region(new Rectangle(0, 0, 0, 0));
            chart.Graphics3D.hasClipRegion = false;

            try
            {


                if (Panel.BorderRound > 0)
                {
                    Rectangle rect = Rectangle.FromLTRB(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right, ClientRectangle.Bottom);
                    rect.Inflate(-1, -1);
                    byte[] pointTypes;
                    PointDouble[] points = chart.Graphics3D.GetClipRoundRectangle(out pointTypes, rect, Panel.BorderRound, Panel.BorderRound, 0);
                    System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(PointDouble.RoundF(points), pointTypes);
                    System.Drawing.Region round = new System.Drawing.Region(path);
                    this.Region = round;
                }
                else
                {
                    this.Region = null;
                }

                chart.DoPanelPaint(g, ClientRectangle);


                if (BackgroundImage != null)
                {
                    g.DrawImage(BackgroundImage, chart.ChartRect);
                }

                ((IChart)this).DoBeforeDraw();


                chart.InternalDraw(g);

                if ((chart.zoom != null) && (chart.zoom.Active))
                {
                    chart.zoom.Draw();
                }

                ((IChart)this).DoAfterDraw();

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Steema needs to add handling code here for this exception: " + ex.Message);
            }
            finally
            {
                chart.graphics3D.ShowImage(g);
                chart.AutoRepaint = old;
            }

        }

Posted: Wed Dec 10, 2008 8:51 am
by narcis
Hello Mike,

Thanks for your feedback. I've added your request to the wish-list to be considered for inclusion in future releases.

When can this be addressed

Posted: Fri May 22, 2009 9:09 pm
by 8739068
The fix I proposed is fairly minor. Would like to see the catch block added. Can you tell me if that will be possible?

Posted: Mon May 25, 2009 11:01 am
by narcis
Hello Mike,

We have done some tests here to check if such checking would affect TeeChart's performance and it doesn't seem to be the case. Which sort of handling code do you have in mind?

Thanks in advance.

suggestion

Posted: Tue May 26, 2009 1:08 pm
by 8739068
Simply what I show above will suffice. Adding the following code just below the 'try' block

Code: Select all

catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Steema needs to add handling code here for this exception: " + ex.Message);
            } 
This should not affect performance since it occurs only when there is an exception. Without the catch, an exception crashes our application.

See my response on December 8, 2008 for the entire
public virtual void Draw(Graphics g)
method

Posted: Wed May 27, 2009 9:12 am
by narcis
Hi Mike,

I think that your suggestion would only work if TeeChart is compiled in debug mode. Therefore this would only be feasible for sourcecode customers which can already implement this. However, we should think about what TeeChart should do if a runtime error is raised when TeeChart is compiled in release mode. It's in release mode that TeeChart is built for clients who are not sourcecode clients.

Agree, but.....

Posted: Wed May 27, 2009 1:05 pm
by 8739068
It seems the consequences of not handling the exception is very bad. It causes an application that is using the TeeChart.dll to crash. If we did not have the source code, we would have to have this bug fixed or find a different tool.

I would consider this a very high priority for non-source code customers.

Posted: Thu May 28, 2009 10:31 am
by narcis
Hello Mike,

Thanks for your suggstion. No non-sourcecode customer complained about that so far. Anyway, I'll add your request to the wish-list to be considered for inclusion in future releases.

Re: Unhandled exception

Posted: Tue Sep 08, 2009 1:31 pm
by 8739068
A good article on exception handling to pass along for anyone interested

http://msdn.microsoft.com/en-us/magazine/cc188720.aspx

Re: Unhandled exception

Posted: Wed Sep 09, 2009 2:50 pm
by narcis
Hi Mike,

Thanks for sharing this article. Anyhow, rather than going that route we would rather reproduce the exception in Steema.TeeChart.Drawing.Graphics3DGdiPlus.Ellipse so that we can find a specific solution to it so we'd appreciate if you found a way to consistently reproduce the issue and could send us a project demonstrating that. Also, have you found other Graphics3DGdiPlus members that also throw exceptions?

Thanks in advance.