Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/molovo/crash
Proper error handling, exceptions and try/catch for ZSH
https://github.com/molovo/crash
exception-handler exceptions zsh zsh-plugin zsh-plugins
Last synced: 9 days ago
JSON representation
Proper error handling, exceptions and try/catch for ZSH
- Host: GitHub
- URL: https://github.com/molovo/crash
- Owner: molovo
- License: mit
- Created: 2017-02-01T22:13:26.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-28T21:47:54.000Z (over 7 years ago)
- Last Synced: 2024-10-13T02:15:30.118Z (24 days ago)
- Topics: exception-handler, exceptions, zsh, zsh-plugin, zsh-plugins
- Language: Shell
- Size: 158 KB
- Stars: 64
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Crash
[![Build Status](https://travis-ci.org/molovo/crash.svg?branch=master)](https://travis-ci.org/molovo/crash)
[![Join the chat at https://gitter.im/molovo/crash](https://badges.gitter.im/molovo/crash.svg)](https://gitter.im/molovo/crash?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)Proper error handling, exceptions and try/catch for ZSH.
![Crash Screenshot](/screenshots/screenshot.png)
## Installation
### [zulu](https://github.com/zulu-zsh/zulu)
```sh
zulu install crash
```### Manual
```sh
git clone https://github.com/molovo/crash crash
cp crash/crash /usr/local/share/zsh/site-functions # Or anywhere else in $fpath
```## Usage
### 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.
```sh
autoload -Uz crash && crash registerthrow TestException 'This is a test' # Will cause the error handler to be displayed
```### Try/catch
Crash comes with the functions `try`, `catch` and `throw`, allowing you to handle exceptions much as you would in a 'proper' programming language.
```sh
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
```## License
Copyright (c) 2016 James Dinsdale (molovo.co)
Crash is licensed under The MIT License (MIT)
## Team
* [James Dinsdale](http://molovo.co)