The following code invokes a powershell script and when the script breaks due to a termination error from powershell script such as "Attempting to perform the InitializeDefaultDrives operation on the 'ActiveDirectory' provider failed." catches the exception but the .NET app crashes.
try
{
output = this.PowerShellEnvironment.Invoke();
}
catch (CmdletInvocationException ex)
{
}
catch (RuntimeException ex)
{
}
catch (Exception ex)
{
}
try
{
output = this.PowerShellEnvironment.Invoke();
}
catch (Exception ex)
{
//handle ex here
}
use following code get the excpetion type and do the operation you want to perform (handle exception etc..) in catch block
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.