您的位置:首页 > 运维架构 > Shell

PowerShell1.0 与2.0中的异常处理比较

2011-12-07 13:52 323 查看

在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

  • 内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
    标签: