Hi,

I have added a try/catch block in the Main() method of my c# window
application to catch all exceptions in the application. But it is no
catching the errors thrown from timer's tick event. My code is give
below:

[STAThread]
static void Main()
{
try
{
Application.Run(new Form1());
}
catch (Exception exec)
{
MessageBox.Show(exec.ToString());
}
}

private void timer1_Tick(object sender, System.EventArgs e)
{
throw new Exception("throwing exception from timer..");
}

Now it shows a windows exception from timer's tick event. Can any on
help me to fix it?

Thanks in advance

--
jjoh
-----------------------------------------------------------------------
jjohn's Profile: http://www.hightechtalks.com/m87
View this thread: http://www.hightechtalks.com/t234875

Re: problem in global catch for all exceptions by Benny

Benny
Wed Feb 01 01:58:05 CST 2006

You need to subscribe to the UnhandledException event on the
AppDomain.CurrentDomain:

In your void Main, add the following line prior to Application.Run.


AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);


public static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs ue) {
Exception e = (Exception) ue.ExceptionObject;
try {
MessageBox.Show(string.Format("{0}\r\n{1}\r\n\r\nStack Trace:\r\n{2}",
e.GetType().FullName, e.Message, e.StackTrace));
}
catch {
}

}



"jjohn" <jjohn.22jdpz@no-mx.forums.yourdomain.com.au> skrev i en meddelelse
news:jjohn.22jdpz@no-mx.forums.yourdomain.com.au...
>
> Hi,
>
> I have added a try/catch block in the Main() method of my c# windows
> application to catch all exceptions in the application. But it is not
> catching the errors thrown from timer's tick event. My code is given
> below:
>
> [STAThread]
> static void Main()
> {
> try
> {
> Application.Run(new Form1());
> }
> catch (Exception exec)
> {
> MessageBox.Show(exec.ToString());
> }
> }
>
> private void timer1_Tick(object sender, System.EventArgs e)
> {
> throw new Exception("throwing exception from timer..");
> }
>
> Now it shows a windows exception from timer's tick event. Can any one
> help me to fix it?
>
> Thanks in advance!
>
>
> --
> jjohn
> ------------------------------------------------------------------------
> jjohn's Profile: http://www.hightechtalks.com/m872
> View this thread: http://www.hightechtalks.com/t2348756
>



Re: problem in global catch for all exceptions by jjohn

jjohn
Wed Feb 01 04:59:04 CST 2006


Hi Benny,

Thanks for your response!

I have added the above code. But it remains the same. Is there an
other way?(or I need to add something with the above code?). Thanks

--
jjoh
-----------------------------------------------------------------------
jjohn's Profile: http://www.hightechtalks.com/m87
View this thread: http://www.hightechtalks.com/t234875


RE: problem in global catch for all exceptions by Brandon

Brandon
Wed Feb 01 12:21:30 CST 2006

what version of VS or .NET framework are you using? I am currently doing this
in a winforms application w/ VS.NET 2k5 and .NET 2.0 framework with no
problems, just tested it as a matter of fact and it works as expected.

"jjohn" wrote:

>
> Hi,
>
> I have added a try/catch block in the Main() method of my c# windows
> application to catch all exceptions in the application. But it is not
> catching the errors thrown from timer's tick event. My code is given
> below:
>
> [STAThread]
> static void Main()
> {
> try
> {
> Application.Run(new Form1());
> }
> catch (Exception exec)
> {
> MessageBox.Show(exec.ToString());
> }
> }
>
> private void timer1_Tick(object sender, System.EventArgs e)
> {
> throw new Exception("throwing exception from timer..");
> }
>
> Now it shows a windows exception from timer's tick event. Can any one
> help me to fix it?
>
> Thanks in advance!
>
>
> --
> jjohn
> ------------------------------------------------------------------------
> jjohn's Profile: http://www.hightechtalks.com/m872
> View this thread: http://www.hightechtalks.com/t2348756
>
>

RE: problem in global catch for all exceptions by AMercer

AMercer
Wed Feb 01 12:45:29 CST 2006

> I have added a try/catch block in the Main() method of my c# windows
> application to catch all exceptions in the application. But it is not
> catching the errors thrown from timer's tick event. My code is given
> below:

I think you need to add handlers for two exceptions, namely
AppDomain.CurrentDomain.UnhandledException
Application.ThreadException
That's what I had to do in FW 1.1. Don't know about FW 2.0.


Re: problem in global catch for all exceptions by jjohn

jjohn
Wed Feb 08 01:01:11 CST 2006


Thanks Mercer!
Application.ThreadException is solved my issue. I also using FW1.1
Thanks so much!

JJoh

--
jjoh
-----------------------------------------------------------------------
jjohn's Profile: http://www.hightechtalks.com/m87
View this thread: http://www.hightechtalks.com/t234875


Re: problem in global catch for all exceptions by jjohn

jjohn
Wed Feb 08 05:00:42 CST 2006


Hi,
Can you please help me one more....
I am having a problem in printing, when I am drawing the picture usin
the following code. It draws correctly on screen, but when I a
printing it prints tiny controls. My code block is given below:

private void PaintCtrl(Control ctrll, Graphics graphics, Rectangle
rectF)
{
Bitmap bitmap = null;
PictureBox pic = ctrl as PictureBox;
if (pic != null)
{
if (pic.Image != null)
{
bitmap = pic.Image as Bitmap;
}
}
if (bitmap == null)
{
bitmap = new Bitmap(ctrl .Width, ctrl .Height);
win32.CaptureWindow(ctrl , ref bitmap);
}

// Make the rectF the size of the bitmap.
PointF[] points =
{ new PointF(rectF.Location.X, rectF.Location.Y) };
graphics.TransformPoints(
CoordinateSpace.Device, CoordinateSpace.Page, points);
points[0].X += bitmap.Width;
points[0].Y += bitmap.Height;
graphics.TransformPoints(
CoordinateSpace.Page, CoordinateSpace.Device, points);
RectangleF bMapRect = new RectangleF(rectF.Location, rectF.Size);
bMapRect.Height = points[0].Y - rectF.Top;
bMapRect.Width = points[0].X - rectF.Left;

graphics.DrawImage(bitmap, bMapRect);
}

Thanks in advance!

JJoh

--
jjoh
-----------------------------------------------------------------------
jjohn's Profile: http://www.hightechtalks.com/m87
View this thread: http://www.hightechtalks.com/t234875


Re: problem in global catch for all exceptions by AMercer

AMercer
Wed Feb 08 06:48:27 CST 2006

> I am having a problem in printing, when I am drawing the picture using
> the following code. It draws correctly on screen, but when I am
> printing it prints tiny controls. My code block is given below:

Sorry, I have no experience with this kind of thing. I suggest you re-post
this question under
dotnet.framework.drawing
You will probably get a response there.