[ Web Proxy ]
URL:
Viewing: https://ja.javascript.info/task/finally-or-code-after [Back]  [Original]

Finally or just the code?
:
Light themeDark theme
DanskEnglishEspaolFranaisIndonesiaItalianoTrkeOzbek

Finally or just the code?

: 5

2

  1. 1 try..catch finally :

    try {
      work work
    } catch (e) {
      handle errors
    } finally {
      
    }
  2. 2 try..catch :

    try {
      work work
    } catch (e) {
      handle errors
    }
    
    

finally

try..catch

try..catch return finally try..catch return

function f() {
  try {
    alert('start');
    return "result";
  } catch (e) {
    /// ...
  } finally {
    alert('cleanup!');
  }
}

f(); // cleanup!

throw :

function f() {
  try {
    alert('start');
    throw new Error("an error");
  } catch (e) {
    // ...
    if("can't handle the error") {
      throw e;
    }

  } finally {
    alert('cleanup!')
  }
}

f(); // cleanup!

finally f


Web Proxy Viewer  |  New URL  |  Original Page