質問

I've an application that's getting gmail email address and password from a database table, and verifying it, before sending any message using those emails, but the following part is returning me an exception, whenever there's any validation error occurs.

new System.Net.NetworkCredential(username, password);

How can I verify that username and password are correct without throwing any exception at runtime?

役に立ちましたか?

解決

This answer was provided in order to ascertain the exact nature of the problem as the code originally posted was insufficient.

According to the documentation the constructor doesn't raise an exception - unless you are using the version that takes a SecureString for the password.

In that case it raises a NotSupportedException if the SecureString class is not supported.

What exception is actually being raised?

他のヒント

Documentation for NetworkCredential(string, string) doesn't say anything about exceptions. Mono's implementation doesn't throw exceptions in constructor either.

Do you get an exception when you try to send an email?

In either case, wrap it in a try/catch block. That's how exceptions are supposed to be handled.
If you're new to exceptions, be sure also to read Eric's post on this matter, it directly relates to your question.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top