# gulp-trycatch-closure

> Enclose the content with a try...catch statement

Latest version **1.0.4** (published 2014-09-25) · 0 weekly downloads

## Install

```sh
npm install gulp-trycatch-closure
pnpm add gulp-trycatch-closure
yarn add gulp-trycatch-closure
bun add gulp-trycatch-closure
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2014-09-25 |
| First published | 2014-06-27 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Ulflander |
| Maintainers | ulflander |
| Keywords | gulpplugin |

## Links

- npm: https://www.npmjs.com/package/gulp-trycatch-closure
- Repository: https://github.com/Ulflander/gulp-trycatch-closure
- Issues: https://github.com/Ulflander/gulp-trycatch-closure/issues
- npm.io page: https://npm.io/package/gulp-trycatch-closure

## Dependencies (2)

- [through](https://npm.io/package/through.md) ^2.3.4
- [gulp-util](https://npm.io/package/gulp-util.md) ^2.2.5

## Recent versions

- 1.0.4 (latest) — 2014-09-25
- 1.0.3 — 2014-09-25
- 1.0.2 — 2014-06-27
- 1.0.1 — 2014-06-27
- 1.0.0 — 2014-06-27

## README

# gulp-trycatch-closure

Enclose JS files content with a "try ... catch" statement.

It allows to easily catch errors on development.

## Install

Install `gulp-trycatch-closure` using NPM, as a development dependency:

```shell
npm install --save-dev gulp-trycatch-closure
```

## Usage

```js
var gulp = require('gulp'),
    concat = require('gulp-concat'),
    trycatch = require('gulp-trycatch-closure');

gulp.task('build', function() {
    // Get all JS files
    return gulp.src(['src/js/*.js'])
        // Enclose their content with a try ... catch statement
        .pipe(trycatch())
        // Concat
        .pipe(concat('build.js'))
        // Send to destination
        .pipe(gulp.dest('dist/'));
});
```

## Usage with gulp-if

```
var gulp = require('gulp'),
    concat = require('gulp-concat'),
    ifif = require('gulp-if'),
    trycatch = require('gulp-trycatch-closure'),

    // Check if we're in dev env
    isDev = process.NODE_ENV !== 'production';

gulp.task('build', function() {
    return gulp.src(['src/js/*.js'])
        .pipe(ifif(isDev, trycatch()))
        .pipe(concat('build.js'))
        .pipe(gulp.dest('dist/'));
});
```

## Change the way to log errors

You can pass to the `trycatch` function an object of options. Here are the available options with their default value:

* `logger` - Way to log the error, default is `console.warn(e);`

## Example of resulting build file:

```js
try {
  
    /* file content */

} catch (e) {
    console.warn(e);
}
```

---
_Source: https://npm.io/package/gulp-trycatch-closure · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
