Click here to Skip to main content
14,491,404 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a routine (class actually) that handles sending emails.

I have a conditional routine that I put in place that will ignore all Certificate errors (it basically just accepts all certificates as valid) but when that routine is turned off (by the user) I want to be able to catch those exceptions and give a nice simple error message rather than the 2 pages of text that get sent back right now.

If it's not that error then I'll need all the error text in order to figure out what's happening and fix it for the client, but this error, being expected, doesn't need all the text.

The Exception I'm trying to catch is:

"System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure"

How can I do that? Forgive me if this is a pretty simple question ... I just can't seem to find an example.

I am using a Try Catch End Try already ... so I know my test to see if this specific exception has occurred will go into the Catch portion of the code ... I just don't know what to test my exception variable against to allow me to adjust my error message appropriately for this single situation without blocking the other exceptions from being handled as I've currently got them coded.

Thanks.
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You haven't shown your code so this is just a guess. but have to you tried:
Try
    ....
Catch ex As AuthenticationException
    ....
End Try
   
Comments
BHort 27-Oct-11 18:42pm
   
Can I have multiple Catch ex As statements? The first being this and then the next being the more general one?
Dave Kreskowiak 27-Oct-11 23:40pm
   
Have you tried it?? Yes, you can. All you have to do is put the cursor on the Try keyword and hit F1. The documentation goes a long way to explaining this stuff.
BHort 28-Oct-11 14:54pm
   
I tried right after posting my comment. Hence my accepting the solution prior to your response.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100