[Howto][C#] ActiveDir - Catch invalid userID

  • Thread starter Thread starter STeve
  • Start date Start date
S

STeve

Hi guys,

In my active directory class I was wondering how I would be able to
catch invalid UserID's entered by the user. For example say if the
user entered in a UserID as a. (well any set of characters followed by
a period), an error gets thrown:

A device attached to the system is not functioning... etc

I was wondering if there is a way to catch this error (instead of just
catching Exception ex) so I could output an invalid UserID message to
the official creating the users.


Thanks in advance,
Steve
 
If I am understanding the issue correctly, you can catch any specific
exceptions that are thrown. i.e. System.ArgumentException,
System.ArgumentOutOfRangeException. For any given method you call, the
documentation often lists possible exceptions that could be thrown. If you
do not get a specific exception, you will need to handle System.Exception.

Once you catch an exception it often makes sense to create and throw your
own custom exception that wraps the original exception.

Scott Caskey
 
Back
Top