Skip to content

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

License

Notifications You must be signed in to change notification settings

MarketingPipeline/TryCatch.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.