Remove repeated multiple nested inner exceptions

OSVBNET 1,386 Reputation points
2022-04-25T19:08:32.957+00:00

Hey, using such code:

Try
...connect to some remote server...
Catch Exception As Exception
MsgBox(Exception.Message)
End Try

Can throw different exceptions, but in some cases, repeated multiple nested inner exceptions will throw like this:

IOException occurred during SSL negotiation. InnerException message follows: An existing connection was forcibly closed by the remote host. InnerException message follows: An existing connection was forcibly closed by the remote host InnerException message follows: An existing connection was forcibly closed by the remote host

I have the same inner exception 3 times with the same message text! This it not very usual, but how can I filter the repeated ones? The message text can be very different so can't use string manipulation.

Any help please? :)
Thanks in advance.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,749 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 32,691 Reputation points Microsoft Vendor
    2022-04-26T03:12:05.11+00:00

    Hi @OSVBNET ,
    If you just want to get non-repeated error information, you can choose to split the string by '.', and then remove the repeated part from the whole.
    I think the first error message should always be surrounded by '.'.
    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.