在PowerShell2.0中允许使用try…catch语句来进行异常处理,那么它与Trap有什么不同呢?下面简要列出:

  • Trap:
    • Designed for admins
    • V1 and V2
    • Introduces a new scope
    • Is “global”, meaning it applies to all code in the same scope, before or after.
    • Does not support rethrow (an empty throw statement throws a special RuntimeException with the message “ScriptHalted”)
  • Try/Catch
    • Designed for developers
    • V2 only
    • Does not introduce a new scope
    • Guarded code is in the try statement block, not the entire scope containing the try statement
    • Supports finally
    • Supports rethrowing exceptions

本文参考资料来源:http://blogs.msdn.com/b/powershell/archive/2009/06/17/traps-vs-try-catch.aspx

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2022-02-01
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2021-05-25
  • 2022-02-12
  • 2022-01-03
  • 2022-02-04
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
相关资源
相似解决方案