Home All Groups Group Topic Archive Search About

exceptions/inner exceptions

Author
20 Jul 2006 4:42 PM
Lance
hi all,
using the following code, i never get a message box showing the error, but the default
error sound is produced (like there should be an accompanying messagebox).

\\\\\\\\\\
Dim FI As FileInfo = _
My.Computer.FileSystem.GetFileInfo(txtSelectedDocument.Text)

Try
My.Computer.FileSystem.CopyDirectory(FI.DirectoryName, _
lblResultText.Text, _
Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, _
FileIO.UICancelOption.ThrowException)
MsgBox("Update is complete.", MsgBoxStyle.Information, _
"Complete.")
Catch ex As Exception
MsgBox("Copying did not finish." & DoubleCrLf & "Error: " _
& ex.InnerException.ToString, MsgBoxStyle.Critical, _
"Failed.")
End Try
\\\\\\\\\\\

how can i get the message box to show up, and to show up with the error?
thanks,
lance

Author
20 Jul 2006 7:00 PM
Cor Ligthert [MVP]
Lance,

Did you try this one,

http://msdn2.microsoft.com/en-us/library/xz2d9afk.aspx

Not catching the exeption in your cancel parameter

I hope this helps,

Cor
Show quoteHide quote
"Lance" <nu***@business.com> schreef in bericht
news:%23ioNvtBrGHA.1552@TK2MSFTNGP02.phx.gbl...
> hi all,
> using the following code, i never get a message box showing the error, but
> the default error sound is produced (like there should be an accompanying
> messagebox).
>
> \\\\\\\\\\
> Dim FI As FileInfo = _
> My.Computer.FileSystem.GetFileInfo(txtSelectedDocument.Text)
>
> Try
> My.Computer.FileSystem.CopyDirectory(FI.DirectoryName, _
> lblResultText.Text, _
> Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, _
> FileIO.UICancelOption.ThrowException)
> MsgBox("Update is complete.", MsgBoxStyle.Information, _
> "Complete.")
> Catch ex As Exception
> MsgBox("Copying did not finish." & DoubleCrLf & "Error: " _
> & ex.InnerException.ToString, MsgBoxStyle.Critical, _
> "Failed.")
> End Try
> \\\\\\\\\\\
>
> how can i get the message box to show up, and to show up with the error?
> thanks,
> lance
>
Author
20 Jul 2006 7:17 PM
Lance
i changed the line

Catch ex As Exception

to

Catch ex As OperationCanceledException


but now when i press the cancel button on the copy directory dialog box, all i get is the
exception helper saying that the TargetInvocationException was unhandled.

i put a breakpoint at the "Catch....:" line to check it out.  the excpetion helper appears
after trying to execute the msgbox line.



Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uRWBd6CrGHA.5108@TK2MSFTNGP05.phx.gbl...
> Lance,
>
> Did you try this one,
>
> http://msdn2.microsoft.com/en-us/library/xz2d9afk.aspx
>
> Not catching the exeption in your cancel parameter
>
> I hope this helps,
>
> Cor
> "Lance" <nu***@business.com> schreef in bericht
> news:%23ioNvtBrGHA.1552@TK2MSFTNGP02.phx.gbl...
>> hi all,
>> using the following code, i never get a message box showing the error, but the default
>> error sound is produced (like there should be an accompanying messagebox).
>>
>> \\\\\\\\\\
>> Dim FI As FileInfo = _
>> My.Computer.FileSystem.GetFileInfo(txtSelectedDocument.Text)
>>
>> Try
>> My.Computer.FileSystem.CopyDirectory(FI.DirectoryName, _
>> lblResultText.Text, _
>> Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, _
>> FileIO.UICancelOption.ThrowException)
>> MsgBox("Update is complete.", MsgBoxStyle.Information, _
>> "Complete.")
>> Catch ex As Exception
>> MsgBox("Copying did not finish." & DoubleCrLf & "Error: " _
>> & ex.InnerException.ToString, MsgBoxStyle.Critical, _
>> "Failed.")
>> End Try
>> \\\\\\\\\\\
>>
>> how can i get the message box to show up, and to show up with the error?
>> thanks,
>> lance
>>
>
>
Author
20 Jul 2006 8:39 PM
Lance
Cor,

I *want* to catch the cancel error, though.

lance

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uRWBd6CrGHA.5108@TK2MSFTNGP05.phx.gbl...
> Lance,
>
> Did you try this one,
>
> http://msdn2.microsoft.com/en-us/library/xz2d9afk.aspx
>
> Not catching the exeption in your cancel parameter
>
> I hope this helps,
>
> Cor
> "Lance" <nu***@business.com> schreef in bericht
> news:%23ioNvtBrGHA.1552@TK2MSFTNGP02.phx.gbl...
>> hi all,
>> using the following code, i never get a message box showing the error, but the default
>> error sound is produced (like there should be an accompanying messagebox).
>>
>> \\\\\\\\\\
>> Dim FI As FileInfo = _
>> My.Computer.FileSystem.GetFileInfo(txtSelectedDocument.Text)
>>
>> Try
>> My.Computer.FileSystem.CopyDirectory(FI.DirectoryName, _
>> lblResultText.Text, _
>> Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, _
>> FileIO.UICancelOption.ThrowException)
>> MsgBox("Update is complete.", MsgBoxStyle.Information, _
>> "Complete.")
>> Catch ex As Exception
>> MsgBox("Copying did not finish." & DoubleCrLf & "Error: " _
>> & ex.InnerException.ToString, MsgBoxStyle.Critical, _
>> "Failed.")
>> End Try
>> \\\\\\\\\\\
>>
>> how can i get the message box to show up, and to show up with the error?
>> thanks,
>> lance
>>
>
>
Author
21 Jul 2006 12:40 PM
Lance
i'd like to be able to properly catch the cancellation of the directory copy, but still no
luck displaying the messagebox (i'm still just only getting the default error chime).  any
other suggestions would be greatly appreciated.

when stepping through the code, it gets to the MsgBox line, and the never actually shows
it.

lance

Show quoteHide quote
"Lance" <nu***@business.com> wrote in message
news:%23ioNvtBrGHA.1552@TK2MSFTNGP02.phx.gbl...
> hi all,
> using the following code, i never get a message box showing the error, but the default
> error sound is produced (like there should be an accompanying messagebox).
>
> \\\\\\\\\\
> Dim FI As FileInfo = _
> My.Computer.FileSystem.GetFileInfo(txtSelectedDocument.Text)
>
> Try
> My.Computer.FileSystem.CopyDirectory(FI.DirectoryName, _
> lblResultText.Text, _
> Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, _
> FileIO.UICancelOption.ThrowException)
> MsgBox("Update is complete.", MsgBoxStyle.Information, _
> "Complete.")
> Catch ex As Exception
> MsgBox("Copying did not finish." & DoubleCrLf & "Error: " _
> & ex.InnerException.ToString, MsgBoxStyle.Critical, _
> "Failed.")
> End Try
> \\\\\\\\\\\
>
> how can i get the message box to show up, and to show up with the error?
> thanks,
> lance
>
Author
21 Jul 2006 12:57 PM
Lance
if i change the messagebox to debug.print then i get the appropriate message in the
immediate window:

"A first chance exception of type 'System.OperationCanceledException' occurred in
Microsoft.VisualBasic.dll
The operation was canceled."

but using a messagebox is causing problems (no box, just sound)

lance

Show quoteHide quote
"Lance" <nu***@business.com> wrote in message
news:uhb%23iLMrGHA.3992@TK2MSFTNGP04.phx.gbl...
> i'd like to be able to properly catch the cancellation of the directory copy, but still
> no luck displaying the messagebox (i'm still just only getting the default error chime).
> any other suggestions would be greatly appreciated.
>
> when stepping through the code, it gets to the MsgBox line, and the never actually shows
> it.
>
> lance
>
> "Lance" <nu***@business.com> wrote in message
> news:%23ioNvtBrGHA.1552@TK2MSFTNGP02.phx.gbl...
>> hi all,
>> using the following code, i never get a message box showing the error, but the default
>> error sound is produced (like there should be an accompanying messagebox).
>>
>> \\\\\\\\\\
>> Dim FI As FileInfo = _
>> My.Computer.FileSystem.GetFileInfo(txtSelectedDocument.Text)
>>
>> Try
>> My.Computer.FileSystem.CopyDirectory(FI.DirectoryName, _
>> lblResultText.Text, _
>> Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, _
>> FileIO.UICancelOption.ThrowException)
>> MsgBox("Update is complete.", MsgBoxStyle.Information, _
>> "Complete.")
>> Catch ex As Exception
>> MsgBox("Copying did not finish." & DoubleCrLf & "Error: " _
>> & ex.InnerException.ToString, MsgBoxStyle.Critical, _
>> "Failed.")
>> End Try
>> \\\\\\\\\\\
>>
>> how can i get the message box to show up, and to show up with the error?
>> thanks,
>> lance
>>
>
>
Author
25 Jul 2006 11:04 AM
Phill W.
Lance wrote:

> using the following code, i never get a message box showing the error

> Catch ex As Exception
> MsgBox("Copying did not finish." & DoubleCrLf & "Error: " _
> & ex.InnerException.ToString, MsgBoxStyle.Critical, _
> "Failed.")

Since you're catching Exception, you can't guarantee that the
InnerException property is going to have a value.  If it arrives as a
null reference, the code that calls "ex.InnerException.ToString" will fail.

Only catch the type of Exception you want, or make sure that you've got
a valid Inner Exception before displaying it, as in

    Catch ex As Exception
       If ex.InnerException Is Nothing Then
          MsgBox("Copying did not finish." & DoubleCrLf _
             & "Error: " & ex.ToString() _
             , MsgBoxStyle.Critical _
             , "Failed." _
             )
       Else
          MsgBox("Copying did not finish." & DoubleCrLf _
             & "Error: " & ex.InnerException.ToString() _
             , MsgBoxStyle.Critical _
             , "Failed." _
             )
       End If

HTH,
    Phill  W.