简体   繁体   中英

catch(Exception e) is not catching exception thrown by managed dll

try
{
    value = System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName; 
}       
catch (Exception e)
{
    //handle exception
}

I am trying to call a method from System.DirectoryServices.AccountManagement.ni.dll to locate the UPN for the user to authenticate the client. However, in the case where the user's password has been changed by an administrator, this dll is throwing an exception and I can't figure out why catch(Exception e) is not handling it. The exception is bubbling up and taking down my application.

Is there something else I need to do to catch this exception?

If the catch block in the code in the question is not being entered, then the only conclusion is that

value = System.DirectoryServices.AccountManagement.UserPrincipal.
    Current.UserPrincipalName; 

does not throw an exception. Perhaps during the execution of this statement an exception is thrown and then caught. But the only sane conclusion that can be reached is that your catch-all handler is not catching anything is that there is nothing to be caught.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM