主頁 > 知識(shí)庫 > PowerShell: Try...Catch...Finally 實(shí)現(xiàn)方法

PowerShell: Try...Catch...Finally 實(shí)現(xiàn)方法

熱門標(biāo)簽:電商外呼系統(tǒng)排名 地圖標(biāo)注審核周期 AI智能電銷機(jī)器人壞處 沈陽ai電銷智能機(jī)器人 如何申請(qǐng)400的電話呀 蘭州電銷機(jī)器人加盟 電話機(jī)器人對(duì)家居行業(yè)幫助大嗎 合肥電銷外呼系統(tǒng)供應(yīng)商 黑暗之魂3地圖標(biāo)注

復(fù)制代碼 代碼如下:

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
        }
    }

使用示例:

復(fù)制代碼 代碼如下:

# 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..."
    }

您可能感興趣的文章:
  • try catch finally的執(zhí)行順序深入分析
  • C#中的try catch finally用法分析
  • 理解javascript中try...catch...finally
  • 雜談try-catch-finally異常處理
  • 再談異常處理try catch finally

標(biāo)簽:河池 隴南 通遼 淮南 常州 黔南 黔南 河北

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PowerShell: Try...Catch...Finally 實(shí)現(xiàn)方法》,本文關(guān)鍵詞  PowerShell,Try...Catch...Finally,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PowerShell: Try...Catch...Finally 實(shí)現(xiàn)方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于PowerShell: Try...Catch...Finally 實(shí)現(xiàn)方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章