473,748 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to walk through InnerExceptions ?

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

Private Sub ShowException(B yVal ex As Exception)
MsgBox(ex.Messa ge)
If ex.InnerExcepti on Is Nothing = False Then _
ShowException(e x.InnerExceptio n)
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 7561
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 GetInnerExcepti on(byref tException As Exception) As String

Dim tReturn As String = String.Empty

If Not Nothing Is tException Then

tReturn = tException.ToSt ring()

If Not Nothing Is tException.Inne rException Then
tReturn = tReturn & GetInnerExcepti on(tException.I nnerException)
End If

End If

Return tReturn

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

Private Sub ShowException(B yVal ex As Exception)
MsgBox(ex.Messa ge)
If ex.InnerExcepti on Is Nothing = False Then _
ShowException(e x.InnerExceptio n)
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 GetInnerExcepti on(byref tException As Exception) As String

Dim tReturn As String = String.Empty

Do While Not tException Is Nothing
tReturn &= tException.ToSt ring()
tException = tException.Inne rException
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 GetInnerExcepti on(byref tException As Exception) As String

Dim tReturn As String = String.Empty

If Not Nothing Is tException Then

tReturn = tException.ToSt ring()

If Not Nothing Is tException.Inne rException Then
tReturn = tReturn & GetInnerExcepti on(tException.I nnerException)
End If

End If

Return tReturn

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

Private Sub ShowException(B yVal ex As Exception)
MsgBox(ex.Messa ge)
If ex.InnerExcepti on Is Nothing = False Then _
ShowException(e x.InnerExceptio n)
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 GetInnerExcepti on(byref tException As Exception) As
String

Dim tReturn As String = String.Empty

Do While Not tException Is Nothing
tReturn &= tException.ToSt ring()
tException = tException.Inne rException
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 GetInnerExcepti on(byref tException As Exception) As
String

Dim tReturn As String = String.Empty

If Not Nothing Is tException Then

tReturn = tException.ToSt ring()

If Not Nothing Is tException.Inne rException Then
tReturn = tReturn & GetInnerExcepti on(tException.I nnerException)
End If
End If

Return tReturn

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

Private Sub ShowException(B yVal ex As Exception)
MsgBox(ex.Messa ge)
If ex.InnerExcepti on Is Nothing = False Then _
ShowException(e x.InnerExceptio n)
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 GetInnerExcepti on(tException As Exception) As String

Dim tReturn As String = String.Empty

Do While Not tException Is Nothing
tReturn &= tException.ToSt ring()
tException = tException.Inne rException
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 GetInnerExcepti on(byref tException As Exception) As
String

Dim tReturn As String = String.Empty

Do While Not tException Is Nothing
tReturn &= tException.ToSt ring()
tException = tException.Inne rException
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 GetInnerExcepti on(byref tException As Exception) As
String

Dim tReturn As String = String.Empty

If Not Nothing Is tException Then

tReturn = tException.ToSt ring()

If Not Nothing Is tException.Inne rException Then
tReturn = tReturn & GetInnerExcepti on(tException.I nnerException)
End If
End If

Return tReturn

End Function

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

Private Sub ShowException(B yVal ex As Exception)
MsgBox(ex.Messa ge)
If ex.InnerExcepti on Is Nothing = False Then _
ShowException(e x.InnerExceptio n)
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
2912
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 os.walk(top, topdown=True): for filename in files: print( "file:" + os.path.join(root, filename) ) for dirname in dirs:
6
4690
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 system is walked. On windows, however, I can only walk one drive at a time (C:\, D:\, etc.). Is there a way to make os.walk() behave on Windows as it behaves on Linux? I'd like to walk the entire file system at once... not one drive at a time. Thanks!
7
4563
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... Can someone explain please? for root, dirs, files in os.walk('/directory/'): print root # print dirs # print files
6
5918
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 to be rather slow. I`m thinking there is a potential for speed-up since I don`t need os.walk to report filenames of all the files in every directory it visits. Is there some clever way to use os.walk or another tool that would provide functionality like os.walk except for the listing of the...
9
2873
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 = "/home/meryl/saved_pages/data" dir=open(savedPagesDirectory, 'r') for file in dir: if (isdir(file)): # get the full path of the file
2
4019
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 root, "consumes", print sum(), print "bytes in", len(files), "non-directory files" if 'CVS' in dirs: dirs.remove('CVS') # don't visit CVS directories
2
3016
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 it :)). As soon as some directory is deleted the iterator of os.walk chokes. OK that is somehow clear to me as it can't be valid anymore since it can't go to the just deleted directory but it is in the iterator.
0
2036
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 can always use os.path.abspath, too. A couple more examples that may help, using os.walk: .... for j in i + i: .... print os.path.join(i, j) .... /var/log/apache2
4
2466
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: ========================================= def walker1(arg, dirname, names): DC_List.append((dirname,'')) os.path.walk('\\\\vcdcflx006\\Flex\\Sites', walker1, 0)
0
8982
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8822
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9528
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9357
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9309
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3298
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2205
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.