472,328 Members | 1,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

How to walk through InnerExceptions?

How can I walk through the InnerExceptions? Would the following code be
correct?

Private Sub ShowException(ByVal ex As Exception)
MsgBox(ex.Message)
If ex.InnerException Is Nothing = False Then _
ShowException(ex.InnerException)
End Sub

I thought I saw a snippet a while ago using a For...Each loop, but I'm
unable to find it again.

*** Sent via Developersdex http://www.developersdex.com ***
Jun 6 '06 #1
5 7450
Hello Terry,

I've not had call to walk over inner exceptions, however, if you really want
to, then you'll need to use a recursive function.

Private Function GetInnerException(byref tException As Exception) As String

Dim tReturn As String = String.Empty

If Not Nothing Is tException Then

tReturn = tException.ToString()

If Not Nothing Is tException.InnerException Then
tReturn = tReturn & GetInnerException(tException.InnerException)
End If

End If

Return tReturn

End Function
How can I walk through the InnerExceptions? Would the following code
be correct?

Private Sub ShowException(ByVal ex As Exception)
MsgBox(ex.Message)
If ex.InnerException Is Nothing = False Then _
ShowException(ex.InnerException)
End Sub
I thought I saw a snippet a while ago using a For...Each loop, but I'm
unable to find it again.

*** Sent via Developersdex http://www.developersdex.com ***

Jun 6 '06 #2
No, there is no need for a recursive function. It can be done just as
easily using a simple loop:

Private Function GetInnerException(byref tException As Exception) As String

Dim tReturn As String = String.Empty

Do While Not tException Is Nothing
tReturn &= tException.ToString()
tException = tException.InnerException
Loop

Return tReturn

End Function
Save the recursion for when it's useful. :)
GhostInAK wrote:
Hello Terry,

I've not had call to walk over inner exceptions, however, if you really
want to, then you'll need to use a recursive function.

Private Function GetInnerException(byref tException As Exception) As String

Dim tReturn As String = String.Empty

If Not Nothing Is tException Then

tReturn = tException.ToString()

If Not Nothing Is tException.InnerException Then
tReturn = tReturn & GetInnerException(tException.InnerException)
End If

End If

Return tReturn

End Function
How can I walk through the InnerExceptions? Would the following code
be correct?

Private Sub ShowException(ByVal ex As Exception)
MsgBox(ex.Message)
If ex.InnerException Is Nothing = False Then _
ShowException(ex.InnerException)
End Sub
I thought I saw a snippet a while ago using a For...Each loop, but I'm
unable to find it again.

*** Sent via Developersdex http://www.developersdex.com ***


Jun 6 '06 #3
Thanks. I knew recursion wasn't necessary because I'd seen it before
done this way.

*** Sent via Developersdex http://www.developersdex.com ***
Jun 6 '06 #4
Hello Göran,

No no no. tException is declared ByRef. You dont wanna be changing it's
value willy-nilly like that. If you want to use a loop like that then pass
the exception ByVal.

-Boo
No, there is no need for a recursive function. It can be done just as
easily using a simple loop:

Private Function GetInnerException(byref tException As Exception) As
String

Dim tReturn As String = String.Empty

Do While Not tException Is Nothing
tReturn &= tException.ToString()
tException = tException.InnerException
Loop
Return tReturn

End Function

Save the recursion for when it's useful. :)

GhostInAK wrote:
Hello Terry,

I've not had call to walk over inner exceptions, however, if you
really want to, then you'll need to use a recursive function.

Private Function GetInnerException(byref tException As Exception) As
String

Dim tReturn As String = String.Empty

If Not Nothing Is tException Then

tReturn = tException.ToString()

If Not Nothing Is tException.InnerException Then
tReturn = tReturn & GetInnerException(tException.InnerException)
End If
End If

Return tReturn

End Function
How can I walk through the InnerExceptions? Would the following code
be correct?

Private Sub ShowException(ByVal ex As Exception)
MsgBox(ex.Message)
If ex.InnerException Is Nothing = False Then _
ShowException(ex.InnerException)
End Sub
I thought I saw a snippet a while ago using a For...Each loop, but
I'm
unable to find it again.
*** Sent via Developersdex http://www.developersdex.com ***

Jun 7 '06 #5
You are right. I didn't notice the byref when I copied the code. There
is no reason to send the reference to the exception by reference. Simply
remove the byref from the method:

Private Function GetInnerException(tException As Exception) As String

Dim tReturn As String = String.Empty

Do While Not tException Is Nothing
tReturn &= tException.ToString()
tException = tException.InnerException
Loop

Return tReturn

End Function
GhostInAK wrote:
Hello Göran,

No no no. tException is declared ByRef. You dont wanna be changing
it's value willy-nilly like that. If you want to use a loop like that
then pass the exception ByVal.

-Boo
No, there is no need for a recursive function. It can be done just as
easily using a simple loop:

Private Function GetInnerException(byref tException As Exception) As
String

Dim tReturn As String = String.Empty

Do While Not tException Is Nothing
tReturn &= tException.ToString()
tException = tException.InnerException
Loop
Return tReturn

End Function

Save the recursion for when it's useful. :)

GhostInAK wrote:
Hello Terry,

I've not had call to walk over inner exceptions, however, if you
really want to, then you'll need to use a recursive function.

Private Function GetInnerException(byref tException As Exception) As
String

Dim tReturn As String = String.Empty

If Not Nothing Is tException Then

tReturn = tException.ToString()

If Not Nothing Is tException.InnerException Then
tReturn = tReturn & GetInnerException(tException.InnerException)
End If
End If

Return tReturn

End Function

How can I walk through the InnerExceptions? Would the following code
be correct?

Private Sub ShowException(ByVal ex As Exception)
MsgBox(ex.Message)
If ex.InnerException Is Nothing = False Then _
ShowException(ex.InnerException)
End Sub
I thought I saw a snippet a while ago using a For...Each loop, but
I'm
unable to find it again.
*** Sent via Developersdex http://www.developersdex.com ***


Jun 7 '06 #6

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

Similar topics

9
by: Marcello Pietrobon | last post by:
Hello, I am using Pyton 2.3 I desire to walk a directory without recursion this only partly works: def walk_files() : for root, dirs, files in...
6
by: rbt | last post by:
More of an OS question than a Python question, but it is Python related so here goes: When I do os.walk('/') on a Linux computer, the entire file...
7
by: KraftDiner | last post by:
The os.walk function walks the operating systems directory tree. This seems to work, but I don't quite understand the tupple that is returned......
6
by: Bruce | last post by:
Hi all, I have a question about traversing file systems, and could use some help. Because of directories with many files in them, os.walk appears...
9
by: silverburgh.meryl | last post by:
i am trying to use python to walk thru each subdirectory from a top directory. Here is my script: savedPagesDirectory =...
2
by: gregpinero | last post by:
In the example from help(os.walk) it lists this: from os.path import join, getsize for root, dirs, files in walk('python/Lib/email'): print...
2
by: Martin Marcher | last post by:
Hello, I'm playing around with os.walk and I made up del_tree(path) which I think is correct (in terms of the algorithm, but not as python wants...
0
by: Jeff McNeil | last post by:
Your args are fine, that's just the way os.path.walk works. If you just need the absolute pathname of a directory when given a relative path, you...
4
by: Jeff Nyman | last post by:
Greetings all. I did some searching on this but I can't seem to find a specific solution. I have code like this: ...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.