473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

exceptions/inner exceptions

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(txtSelectedDocu ment.Text)

Try
My.Computer.FileSystem.CopyDirectory(FI.DirectoryN ame, _
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
Jul 20 '06 #1
6 1696
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.comschreef in bericht
news:%2****************@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(txtSelectedDocu ment.Text)

Try
My.Computer.FileSystem.CopyDirectory(FI.DirectoryN ame, _
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

Jul 20 '06 #2
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.

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:uR**************@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.comschreef in bericht
news:%2****************@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(txtSelectedDoc ument.Text)

Try
My.Computer.FileSystem.CopyDirectory(FI.Directory Name, _
lblResultText.Text, _
Microsoft.VisualBasic.FileIO.UIOption.AllDialog s, _
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


Jul 20 '06 #3
Cor,

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

lance

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:uR**************@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.comschreef in bericht
news:%2****************@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(txtSelectedDoc ument.Text)

Try
My.Computer.FileSystem.CopyDirectory(FI.Directory Name, _
lblResultText.Text, _
Microsoft.VisualBasic.FileIO.UIOption.AllDialog s, _
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


Jul 20 '06 #4
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.comwrote in message
news:%2****************@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(txtSelectedDocu ment.Text)

Try
My.Computer.FileSystem.CopyDirectory(FI.DirectoryN ame, _
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

Jul 21 '06 #5
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

"Lance" <nu***@business.comwrote in message
news:uh****************@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.comwrote in message
news:%2****************@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(txtSelectedDoc ument.Text)

Try
My.Computer.FileSystem.CopyDirectory(FI.Directory Name, _
lblResultText.Text, _
Microsoft.VisualBasic.FileIO.UIOption.AllDialog s, _
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


Jul 21 '06 #6
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.
Jul 25 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
24
by: mag31 | last post by:
Is there any way to find out if a particular .net function will throw an exception without first generating the exception? I am using structured exception handling i.e. try catch finally blocks...
7
by: Kenny Cutter | last post by:
Hi group, I am quite new to exceptions in .NET and I am a bit confused of how to use the inner exceptions. Could anyone explain? Let's say I have a function that takes a double (X) that is not...
2
by: Sue | last post by:
I've got a simple Application_OnError routine set up as a generic error trap for web applications running on IIS server (VS 2003) that logs error info and the text of the first inner exception....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.