Hi,
I have a GUI which consists of several actions (like getting ad users for textbox input etc).
Each action has a try cath built in, the catch consists of a function set-catch (below what it is doing). The set-catch is loaded in the globals.ps1
It works, BUT the line number it is stating, is wrong. F.e. when error is showing (in Powershell Studio) at line 150, the error in the gui shows line 365.
Please advise howto get the set-catch show the correct error line.
J.
---
function Set-Catch
{
$line = $_.InvocationInfo.ScriptLineNumber
Add-logs "$_.Exception.Message at line $line"
}
Catch correct error line in PS GUI?
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Catch correct error line in PS GUI?
PowerShell Studio translates the line number to the editor line. The actual line in the generated script in your case 365, but that pertains to line 150 in the editor view of the form.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Catch correct error line in PS GUI?
Is there a way to make them match so I can easily get the correct line?
Re: Catch correct error line in PS GUI?
You could export the script and run that directly (Ribbon->Deploy->Export->Export to File). But I don't recommend editing the file.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Catch correct error line in PS GUI?
Please clarify what you mean by that.
Export what script? Note: goal is to make the GUI show the exact PS Studio error line so when a user of the form/GUI has an error, I can find the error at the correct location.
Export what script? Note: goal is to make the GUI show the exact PS Studio error line so when a user of the form/GUI has an error, I can find the error at the correct location.
Re: Catch correct error line in PS GUI?
Ok, I see, export the full project to a file? Using exe right now and only for this feature using a ps1 ... isn't really worth it.
So that's the only option then?
So that's the only option then?
Re: Catch correct error line in PS GUI?
I recommend including the call stack, that way will help you determine which GUI is causing the exception. Otherwise there is no way for you to map the line to the right project file.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Catch correct error line in PS GUI?
Can you clarify what you mean by "call the stack" ... and how that should be done?
Re: Catch correct error line in PS GUI?
It is called the "call stack" and is a property of the exception object.
$_.Exception.StackTrace
https://msdn.microsoft.com/en-us/librar ... .110).aspx
$_.Exception.StackTrace
https://msdn.microsoft.com/en-us/librar ... .110).aspx
Re: Catch correct error line in PS GUI?
Thanks!
Added it like this
$line = $_.InvocationInfo.ScriptLineNumber
$exceptionstacktrace = $_.Exception.StackTrace
Add-logs "$_.Exception.Message at line $line `n ExceptionStackTrace = $exceptionstacktrace"
Will see what it gives
Added it like this
$line = $_.InvocationInfo.ScriptLineNumber
$exceptionstacktrace = $_.Exception.StackTrace
Add-logs "$_.Exception.Message at line $line `n ExceptionStackTrace = $exceptionstacktrace"
Will see what it gives