New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: try without catch … #555

Closed
baslr opened this Issue Apr 28, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@baslr

baslr commented Apr 28, 2016

'use strict';

class Foo {
  constructor(i) {
    this.i = i;
  }

  bar() {
    console.log('bared');
  }
}

const arr = [new Foo(1), new Foo(2), new Foo(3)];

arr.find( (itm) => itm.i == 2).bar(); // ok

arr.find( (itm) => itm.i == 4).bar(); // TypeError

// fix with 
try arr.find( (itm) => itm.i == 4).bar();

// instead of
try { arr.find( (itm) => itm.i == 4).bar(); } catch(e) {};


// example 2, class function
// instead of
  start(uuid) {
    const vm = this.vm(uuid);
    if (!vm) return;
    vm.start();
  }

// it could be
  start(uuid) {
    try this.vm(uuid).start();
  }

// since sometimes, we just want to try and dont care if it fails
// so give it a try.

@baslr baslr closed this Apr 28, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment