Comando
Try / Catch / Finally
Estrutura de tratamento de exceções. O bloco Try contém o código a executar. Se uma exceção ocorrer, o fluxo vai para Catch (se existir). O bloco Finally é sempre executado ao final, independentemente de exceção. Um bloco Try deve ter ao menos Catch ou Finally.
Try { ... } Catch { ... } Finally { ... }
Exemplos
// Estrutura completa:
Try {
Run('notExists.exe')
}
Catch {
MessageBox($exception)
}
Finally {
Output('Fim da execução')
}
// Estrutura com retry:
int $tentativas = 0
Try {
OpenBrowser('https://sistema.empresa.com')
WebClick('#btnEntrar')
WaitElement('#dashboard', 15)
}
Catch {
Output('Erro: ' + $exception)
If ($tentativas < 3) {
$tentativas++
Delay(1000)
// Fecha o browser pois irá abrir novamente
CloseBrowser()
Retry
}
SaveScreenshot(@'C:\logs\erro.png')
Throw($exception)
}
Finally {
CloseBrowser()
}