Exception not caught when using PowerShell command line but caught as expected when using PowerShell ISE -



Exception not caught when using PowerShell command line but caught as expected when using PowerShell ISE -

i running powershell 2.0.

i have powershell script adds record database , returns id of record added. record id returned property called new_deal_id within datarow object (called resultset).

if there problem on database end possible new_deal_id property not set, or doesn't exist @ all.

to counter scenario wrapped reading of property in try/catch block shown here.

try { $erroractionpreference = "stop" $resultset = read-databasedata -odbccommand $odbccommand -sqlquery $sql $newdealid = $resultset.new_deal_id } grab { throw } { $erroractionpreference = "continue" }

if run script using powershell ise or powergui exception shown below gets caught when property doesn't exist

property 'new_deal_id' cannot found on object. create sure exists. @ line:1 char:12 + $resultset. <<<< newdeal + categoryinfo : invalidoperation: (.:operatortoken) [], parentcontainserrorrecordexception + fullyqualifiederrorid : propertynotfoundstrict

however if run script powershell command line exception not caught , script continues if no error occurred.

why powershell command line not catching exception when property doesn't exist?

this because dont have strict mode enabled in console running script in. (powershell , ise utilize different profiles)

to enable strict mode utilize set-strictmode cmdlet.

example:

set-strictmode -version latest

powershell powershell-v2.0

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -