I'm trying to gracefully exit the program if the username/password is incorrect or (ORA-01017) but the script hangs when getting an error. My proposed error is in the try section of the code then the entire script hangs. I thought the catch is suppose to throw the exception. Ideally I will create a for loop that will connect to each database and if there is an error just capture the error and go on to the next. But right now just testing the try/catching the error option. Also, I'm encrypting the password. Any ideas or suggestions
enter code here
function Start-Something
{
$User = Read-Host -Prompt 'Input the Oracle database user name'
$psswd = Read-Host -Prompt 'Input Oracle database Password:' -AsSecureString
$cryptpasswd = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($psswd))
Write-Host "###############################################"
Write-Host Connecting to Oracle Database: testdb -ForegroundColor Green
sqlplus -s $User/$cryptpasswd@$line '@C:\Users\my\Documents\Scripts\oracledbinfo.sql'
Write-Host "###############################################"
Write-Host " ###########################################"
}
try
{
Start-Something
}
catch
{
Write-Output "Something threw an exception"
Write-Output $_
}
try { Start-Something -ErrorAction Stop } catch { Write-Output "Something threw an exception or used Write-Error" Write-Output $_ }