国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PowerShell > 正文

PowerShell: Try...Catch...Finally 實現方法

2020-03-26 19:25:27
字體:
來源:轉載
供稿:網友

 

復制代碼 代碼如下:

function Try
    {
        param
        (
            [ScriptBlock]$Command = $(throw "The parameter -Command is required."),
            [ScriptBlock]$Catch   = { throw $_ },
            [ScriptBlock]$Finally = {}
        )

        & {
            $local:ErrorActionPreference = "SilentlyContinue"

            trap
            {
                trap
                {
                    & {
                        trap { throw $_ }
                        &$Finally
                    }

                    throw $_
                }

                $_ | & { &$Catch }
            }

            &$Command
        }

 

        & {
            trap { throw $_ }
            &$Finally
        }
    }

 

使用示例:

 

復制代碼 代碼如下:

# Example usage

 

    Try {
        echo " ::Do some work..."
        echo " ::Try divide by zero: $(0/0)"
    } -Catch {
        echo "  ::Cannot handle the error (will rethrow): $_"
        #throw $_
    } -Finally {
        echo " ::Cleanup resources..."
    }

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 青海省| 土默特左旗| 成都市| 师宗县| 澄江县| 新乐市| 东海县| 永城市| 金昌市| 东乡族自治县| 安义县| 虹口区| 茂名市| 茌平县| 南平市| 忻州市| 合作市| 台山市| 鞍山市| 云龙县| 宁化县| 长武县| 武平县| 华容县| 新竹县| 永新县| 昆明市| 抚顺县| 淮滨县| 佛山市| 安陆市| 玛多县| 西盟| 襄垣县| 晋中市| 大荔县| 黄山市| 汽车| 长宁县| 平原县| 东乡|