Hndling Exceptions From DrapDrop Handler

  • Thread starter Thread starter Murthy
  • Start date Start date
M

Murthy

Hi All,

How do i catch the exception that has been thrown from my DragDrop event
handler.


The exception is fired from the following function.

private void richTextBox1_DragDrop(object sender, DragEventArgs e)

{

try{

///some code....}

catch(Exceptio e){

throw ex;}

}



I have tried with ThreadException



Application.ThreadException += new
ThreadExceptionEventHandler(ThreadExceptionHandler);



I have also tried with Unhandled Exception handler.



// Add the event handler for handling non-UI thread exceptions to the event.

AppDomain.CurrentDomain.UnhandledException +=

new UnhandledExceptionEventHandler(UnhandledExceptionHandler);



Both of these do not catch the exception.



Can some one suggest me ?
 
Murthy said:
Hi All,

How do i catch the exception that has been thrown from my DragDrop event
handler.


The exception is fired from the following function.

private void richTextBox1_DragDrop(object sender, DragEventArgs e)

{

try{

///some code....}

catch(Exceptio e){

throw ex;}

}

Hi Mirthy,

Since the operating system is running the event method, any exception not
caught or thrown will be eaten by the operating system. This happens for all
event methods. Whatever you want to do in case of a dragdrop exception you
need to do it from the catch block inside the event method.
 
Hi Morten,


I am developing a user control that will be consumed by clients. I want to
allow users to drag only 1 image and throw an exception when multiple files
are dragged.

private void richTextBox1_DragDrop(object sender, DragEventArgs e)
{
throw (new Exception("can not drag multiple files"));
}

Now this exception has to be caught by the client of this control and
display his own message or something like that.

I am currently testing my component with a client i have and ia m trying to
catch the the exception thrown when multiple files are dragged , but i am
not able to do so.
 
I think you have to handle the AllowedEffect of the DragEnter event for this,
and display the effect indicating a drop is not allowed.
 
Back
Top