Proper error handling, exceptions and try/catch for ZSH
Switch branches/tags
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
screenshots Add screenshot to README Feb 2, 2017
tests Fix broken test Mar 28, 2017
.travis.yml Fix ZUnit download URL in .travis.yml Mar 28, 2017
.zunit.yml Add some simple tests Feb 2, 2017
LICENSE First commit Feb 1, 2017 Add badges to README Feb 2, 2017
crash Bump version Feb 5, 2017


Build Status Join the chat at

Proper error handling, exceptions and try/catch for ZSH.

Crash Screenshot



zulu install crash


git clone crash
cp crash/crash /usr/local/share/zsh/site-functions # Or anywhere else in $fpath


Set up the global error handler

Crash comes with a global error handler, which prints a readable error and stack trace both for user-created exceptions and traditional shell exit codes.

autoload -Uz crash && crash register

throw TestException 'This is a test' # Will cause the error handler to be displayed


Crash comes with the functions try, catch and throw, allowing you to handle exceptions much as you would in a 'proper' programming language.

autoload -Uz crash && crash register

# The function we're going to call
function do_something() {
  echo 'Start to do something...'
  throw RainbowException 'Unicorns!'
  echo 'This message will never be displayed'

# A function to handle any caught exceptions
function error_handler() {
  local exception="$1" message="${(@)@:2}"

  echo $exception # RainbowException
  echo $message   # Unicorns!

try do_something
catch RainbowException error_handler


Copyright (c) 2016 James Dinsdale (

Crash is licensed under The MIT License (MIT)