简体   繁体   English

catch(Exception e)不捕获托管dll引发的异常

[英]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. 我正在尝试从System.DirectoryServices.AccountManagement.ni.dll中调用一个方法,以找到用于用户身份验证客户端的UPN。 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. 但是,在管理员更改了用户密码的情况下,此dll引发异常,我无法弄清楚为什么catch(Exception e)不处理该异常。 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 如果未输入问题代码中的catch块,则唯一的结论是

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. 但是唯一可以得出的合理结论是,所有捕获的处理程序都没有捕获任何东西,就是没有任何东西可以捕获。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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