I have a problem with my PowerShell code. Sometimes -for whatever reason- my script jumps right into the finally block wihtout any error message from the catch block. This is my PowerShell Code:
try
{
$sleepTime = $reservationDuration - $prepareTime
(get-date -format hh:mm:ss)+"`tinfo:`tstart sleep before warning VIP sleep-time:"+$sleepTime | out-file $logFilePath -append
start-sleep -s $sleepTime
(get-date -format hh:mm:ss)+"`tinfo:`tsleeptime over" | out-file $logFilePath -append
}
catch
{
(get-date -format hh:mm:ss)+"`terror:`tchaught exception: "+$error[0] | out-file $logFilePath -append
}
finally{
(get-date -format hh:mm:ss)+"`tinfo:`tFinally" | out-file $logFilePath -append
}
As you see I'm writing some log files in order to see what happened. I'm always getting right int values in my $sleepTime variable. However sometimes it jumps right into the finally block without writing "sleeptime over.." or even "chaught exception..."