Some questions about exceptions

Posted on
  • Hi, Gordon.

    I'd like to ask a bit of questions about exeptions:

    • the built-in class Error has a field named 'type'; what kind of errors can it show?
      is it possible to see a list with kinds of errors anywhere?
      i've tried to catch some errors and all of them were simply 'Error' :-)
    • is it possible to catch an 'Out of memory' error?
      standart "try..catch" block can't intercept it. It's not a great to get
      a broken program by this fault.


  • And one more question.
    First of all a bit of pictures:
    this one

    and one more

    When I try to throw an error and an any block '{//some operators}' is behind the 'throw' block then all operators that go after this 'any block' become executable and thrown error is lost! (see picture one)
    If there is no block with braces after 'throw', all works properly (see picture two)

  • This is wrong message. I don't know how to delete it...

  • Hi,

    The built-in Error class is really just a way to handle SyntaxError,ReferenceError,etc without using up too much extra memory. I'm afraid you can't catch out of memory errors... Almost by definition there's no memory left even to allocate an Error class to throw! If you are continuously appending to strings the best bet is to consult process.memory() every so often.

    Thanks for letting me know about Exceptions - they've been added to Espruino relatively recently and it looks like there are still some glitches to iron out. I've filed a bug for this and I'll try and fix it for the next release.

  • Good. I've understood. I'll wait the new release. Actually exceptions are good tool to make a reliable programm.

    Is any quick way to get to know how many words (bytes) requires the object/variable?

    By the way the 1v69 release works properly on HY-STM32_24VE

  • If there isn't a function to tell us how many memory units a variable (obviously, object/arrays/functions are the interesting ones) is using, there should be.

  • I don't think there is right now, but I was planning on adding it. I've just put an 'issue' in for it.

  • Fixed now (including adding an E.getSizeOf function). It'll be in 1v70

  • Great. I'm waiting... :-)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Some questions about exceptions

Posted by Avatar for Uhv @Uhv