MarketingPipeline / TryCatch.js

A JavaScript library to handle errors in a more structured way.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TryCatch.js

Repo Banner for TryCatch.js
Show your support!

TryCatch.js is a JavaScript library to help you handle your errors in a more clean & structured way.

Example and usage

How to use TryCatch.js:

import {tryCatch} from 'https://cdn.jsdelivr.net/gh/MarketingPipeline/TryCatch.js@v1.0.0/dist/trycatch.min.js';
// Example 1: try-catch-finally
tryCatch(
  function() {
    // some code that may throw an exception
  },
  function(e) {
    // handle the exception
  },
  function() {
    // code that is always executed, whether or not an exception is thrown
  }
);

// Example 2: try-catch-else-finally
tryCatch(
  function() {
    // some code that may throw an exception
  },
  function(e) {
    // handle the exception
  },
  function() {
    // code that is always executed, whether or not an exception is thrown
  },
  function() {
    // code that is executed if the try block returns undefined
  }
);

// Example 3: try-catch
tryCatch(
  function() {
    // some code that may throw an exception
  },
  function(e) {
    // handle the exception
  }
);

// Example 4: try-finally
tryCatch(
  function() {
    // some code that may throw an exception
  },
  null,
  function() {
    // code that is always executed, whether or not an exception is thrown
  }
);

Contributing GitHub contributors

Want to improve this? Create a pull request with detailed changes / improvements! If approved you will be added to the list of contributors of this awesome project!

See also the list of contributors who participate in this project.

License GitHub license

This project is licensed under the MIT License - see the LICENSE file for details.

About

A JavaScript library to handle errors in a more structured way.

License:MIT License


Languages

Language:JavaScript 100.0%