GithubHelp home page GithubHelp logo

anthrax3 / crash Goto Github PK

View Code? Open in Web Editor NEW

This project forked from molovo/crash

0.0 0.0 0.0 162 KB

Proper error handling, exceptions and try/catch for ZSH

License: MIT License

Shell 100.00%

crash's Introduction

Crash

Build Status Join the chat at https://gitter.im/molovo/crash

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

Crash Screenshot

Installation

zulu

zulu install crash

Manual

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.

autoload -Uz crash && crash register

throw 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.

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 [email protected] (molovo.co)

Crash is licensed under The MIT License (MIT)

Team

crash's People

Contributors

molovo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.