1

It's possible to force Exit of a function Parent that call a Function Child, from function Child?
Example code:

function Parent
{
   Write-Host "I'm Calling Parent Function"
   Child
   Write-Host "Code...Code..."
}

function Child
{
   Write-Host "I'm Calling Child Function"
   # END function:Parent
   Write-Host "Parent Ended!"
}

PS> Parent
PS> I'm Calling Parent Function
I'm Calling Child Function
Parent Ended!

Any Idea?

1
  • Not without either returning a value which the parent then checks to see whether it should continue execution or not, or by throwing an terminating exception from the Child method. Of course, both of these approaches would also ensure Child is also ended. Child will always end before Parent will end. Commented Mar 27, 2014 at 10:05

1 Answer 1

1

try this ( using break I think is the dos command or an internal powershell command because get-command break returns error)

function Child
{
   Write-Host "I'm Calling Child Function"
   break
   Write-Host "Parent Ended!"
}
Sign up to request clarification or add additional context in comments.

1 Comment

Maybe that's the command from help about_break, but they don't mention this behavior (or I missed it). Glad you found it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.