ManojRK
ManojRK

Reputation: 962

How to throw an exception in ZSH

I am writing a function and I want to throw an exception when the input is invalid. When I googled I found that there is a throw MyException command but when I try to use it like this:

#!  /usr/bin/zsh
throw Exception

The script throws the following error:

$ ./test.sh                         
./test.sh:2: command not found: throw

Is there an mechanism to throw error in ZSH? If so are there any resources?

Upvotes: 1

Views: 1565

Answers (1)

chepner
chepner

Reputation: 531808

throw and catch must be loaded first; they aren't built directly into the shell.

autoload throw catch

They are documented in zshcontrib(1), under EXCEPTION HANDLING, although it isn't immediately obvious that they need to be loaded.

Upvotes: 2

Related Questions