crash icon indicating copy to clipboard operation
crash copied to clipboard

Allow try/catch statements to be nested

Open molovo opened this issue 7 years ago • 1 comments

This may or may not be possible. The try command needs to launch a subprocess to allow the exception to be caught, which means that modifying the global environment is not possible. To allow statements to be nested we'd need to maintain an 'exception stack' in an array, but cannot do this in its current form due to the use of a subprocess. Thrown exceptions are currently reported back to the global process by echoing the exception and message, so we could maintain the stack outside of the try block, but my first attempt at this didn't work. Something to look into.

molovo avatar Feb 06 '17 12:02 molovo

not really true. You can use named pipes for it. If I understand your prob right. This way command is not running in a subprocess.

PIPE=$(mktemp -u)
mkfifo $PIPE
# attach it to file descriptor 3
exec {hlpr}<>$PIPE
# unlink the named pipe
rm $PIPE
command >&$hlpr
echo -ne $'\0' >&$hlpr
read -d$'\0' -u $hlpr output;
# close fd
exec {hlpr}>&-

daCyberpunk avatar Oct 31 '20 22:10 daCyberpunk