By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

Unhandled exception while dragging

P: n/a
I do not understand why when a dragging operation is started with
DoDragDrop, no exception is handled.
The following lines illustrate what I mean. In Form2_DragDrop event, I raise
an exception at the line "int b=1/a" (so the message After Exception will
not be shown). Why this exception will be unhandled ?

using System;
using System.Windows.Forms;

public class Form2 : System.Windows.Forms.Form {
[STAThread]
static void Main() {
Application.Run(new Form2());
}

public Form2() {
this.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.Form2_ MouseDown);
this.DragDrop += new
System.Windows.Forms.DragEventHandler(this.Form2_D ragDrop);
this.DragEnter += new
System.Windows.Forms.DragEventHandler(this.Form2_D ragEnter);
this.AllowDrop = true;
}

private void Form2_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e) {
DoDragDrop(this,DragDropEffects.All);
}

private void Form2_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e) {
e.Effect=DragDropEffects.Copy;
}

private void Form2_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e) {
int a=0;
MessageBox.Show("Before exception");
int b=1/a;
MessageBox.Show("After exception");
}
}
Ludovic SOEUR
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Ludovic,

Form2_DragDrop is called by Windows, so any unhandled exception will be
handled by Windows, so nothing appears to have happened.

If you on the other hand call Form2_DragDrop directly you will get the
Exception.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

P: n/a
Thanks for your answer that helped me to understand why it was not working.

But is there a way to handle this exception ? Not with a try catch in
Form2_DragDrop event with a message box but with a throw to the global
application ?

Thanks in advance.
Ludovic Soeur.

"Morten Wennevik" <Mo************@hotmail.com> a écrit dans le message de
news:opsnmv8vi6klbvpo@pbn_computer...
Hi Ludovic,

Form2_DragDrop is called by Windows, so any unhandled exception will be
handled by Windows, so nothing appears to have happened.

If you on the other hand call Form2_DragDrop directly you will get the
Exception.

--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #3

P: n/a
Not to my knowledge, though I may be very wrong on this. Strictly
speaking, it is Windows that has performed an illegal action when running
part of your code, not your application.
On Mon, 14 Mar 2005 17:04:15 +0100, Ludovic SOEUR
<Lu***********@hotmail.com> wrote:
Thanks for your answer that helped me to understand why it was not
working.

But is there a way to handle this exception ? Not with a try catch in
Form2_DragDrop event with a message box but with a throw to the global
application ?

Thanks in advance.
Ludovic Soeur.

"Morten Wennevik" <Mo************@hotmail.com> a écrit dans le message de
news:opsnmv8vi6klbvpo@pbn_computer...
Hi Ludovic,

Form2_DragDrop is called by Windows, so any unhandled exception will be
handled by Windows, so nothing appears to have happened.

If you on the other hand call Form2_DragDrop directly you will get the
Exception.

--
Happy Coding!
Morten Wennevik [C# MVP]



--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.