Code Monkey home page Code Monkey logo

Comments (4)

gfwilliams avatar gfwilliams commented on June 20, 2024

Thanks for tracking this down!

It seems that a finally block are only executed if the try/catch block had no control flow statements in them.

Is it any control flow statements, like if/whole/do/for/etc, or literally just return that's not working?

from espruino.

idobh2 avatar idobh2 commented on June 20, 2024

@gfwilliams It seems that return, break and continue are the problematic statements. I ran tests in the Web IDE using the Bangle.js emulator.
These are examples where finally is not executed:

// Not reaching finally block
(() => {
  try {
    console.log("testing return...");
    return;
  } finally {
    console.log("return success");
  }
})();

(() => {
  do {
    try {
      console.log("testing break...");
      break;
    } finally {
      console.log("break success");
    }
  } while (false);
})();

(() => {
  do {
    try {
      console.log("testing continue...");
      continue;
    } finally {
      console.log("continue success");
    }
  } while (false);
})();

And these are cases where it is executed correctly

// Reaching finally block
(() => {
  try {
    console.log("testing if...");
    let someVariable = 0;
    if (true) {
      someVariable = 1;
    }
    if (false) {
      someVariable = 0;
    }
  } finally {
    console.log("if success");
  }
})();

(() => {
  try {
    console.log("testing while...");
    let i = 0;
    while (i < 1) {
      i++;
    }
  } finally {
    console.log("while success");
  }
})();

(() => {
  try {
    console.log("testing do-while...");
    let i = 0;
    do {
      i++;
    } while (i < 2);
  } finally {
    console.log("do-while success");
  }
})();

(() => {
  try {
    console.log("testing for...");
    for (let i = 0; i < 1; i++) {
    }
  } finally {
    console.log("for success");
  }
})();

(() => {
  try {
    console.log("testing throw...");
    throw new Error();
  } catch (e) {
    throw new Error();
  } finally {
    console.log("throw success");
  }
})();

I've confirmed all of them are executed expected in chrome

from espruino.

gfwilliams avatar gfwilliams commented on June 20, 2024

Thanks! I'm pretty sure that's now fixed.

from espruino.

idobh2 avatar idobh2 commented on June 20, 2024

@gfwilliams thanks! confirmed to be working here as well :)

from espruino.

Related Issues (20)

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.