Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: return up two levels?



Please don't use that technique unless it's in the context of something
atypical like a debugger. It's a really bad software pattern. It's spooky
action at a distance. It's a form of monkey-patching. it practically
guarantees hard to debug errors. Plus a large number of other problems.
Don't do it. Be explicit about return values. If you want a caller of
function2 to exit immediately have function2 return non-zero and test for
that. For example,

function2() { print I failed to do my job; return 1 }
function1() { if ! function2; then; print unexpected failure; return 0; fi;
print life is good }



On Mon, Mar 10, 2014 at 8:00 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:

> On 03/10/2014 12:42 PM, Peter Stephenson wrote:
>
> Peter:
>
>> function1() { function2; print Doesn\'t get called; }
>> function2() { trap 'return' EXIT; print Does get called; }
>>
> Thanks, that about does it. I've not used traps up till now.
>
> BTW I'm enjoying  your book. Hats off to Oliver as well of course.
>
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank


Messages sorted by: Reverse Date, Date, Thread, Author