Unhandled exception

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

Unhandled exception

Post by Mike Jones » Fri Mar 07, 2008 4:08 pm

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.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Mar 11, 2008 11:38 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

Unhandled Exception support thread continued

Post by Mike Jones » Tue Mar 11, 2008 3:09 pm

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

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

Estimate when this could be addressed

Post by Mike Jones » Tue Dec 09, 2008 8:46 pm

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

        }

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Dec 10, 2008 8:51 am

Hello Mike,

Thanks for your feedback. I've added your request to the wish-list to be considered for inclusion in future releases.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

When can this be addressed

Post by Mike Jones » Fri May 22, 2009 9:09 pm

The fix I proposed is fairly minor. Would like to see the catch block added. Can you tell me if that will be possible?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon May 25, 2009 11:01 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

suggestion

Post by Mike Jones » Tue May 26, 2009 1:08 pm

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed May 27, 2009 9:12 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

Agree, but.....

Post by Mike Jones » Wed May 27, 2009 1:05 pm

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.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu May 28, 2009 10:31 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

Re: Unhandled exception

Post by Mike Jones » Tue Sep 08, 2009 1:31 pm

A good article on exception handling to pass along for anyone interested

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Unhandled exception

Post by Narcís » Wed Sep 09, 2009 2:50 pm

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply