Problem in exception handling RRS feed

  • Pergunta

  • I made this script that tests the real-time connection to the server of a game. But sometimes the connection fails and throws an exception.

    I put the code block within a try-catch, but the error keeps popping up on the screen whenever the connection fails and do not know what to do. Thank you for helping me!

    Code link and details of OS below:

    Windows 10 1607 (14393,351) x64
    PowerShell 5.1.14393.206

    while ($true){
    	$hora = get-date -UFormat “%H:%M:%S”
        try {
            $ms = ((Test-Connection $ip -Count 1).responseTime) + 4
            if ($ms -lt 100) {
    		    write-host "$hora ─►  $ms ms  █"
            else {
    		    write-host "$hora ─►  $ms ms  █" -ForegroundColor Red
    		    write-output "$hora`: $ms ms" >> "$home\Desktop\NetLog.log"
        catch {
            write-host "$hora`: ERRO" -ForegroundColor Red
            write-output "$hora`: FALHA - $ms" >> "$home\Desktop\NetLog.log"
    	Start-Sleep 1

    segunda-feira, 7 de novembro de 2016 20:40


Todas as Respostas