One idea I had that could be a component of the solution would be that all 
spec-thrown exceptions get an extra flag. So e.g.

```js
try {
  iDoNotExist();
} catch (e) {
  assert(e.thrownBySpecMechanisms);
}
```

You would generally use this via

```js
try {
  someOperation();
} catch (e) {
  if (e.thrownBySpecMechanisms) {
    // I am only prepared to handle operational failures, not typos or
    // trying to write to non-writable properties or the like.
    throw e;
  }

  handleOperationalError(e);
}
```

You could then imagine some syntactic sugar of the sort

```js
try {
  someOperation();
} recover (e) {
  // `recover` only handles non-spec-thrown exceptions.
  handleOperationalError(e);
}
```

This would be an alternative to the requirement that all authors suddenly agree 
on a new flag (or worse, subclass) to distinguish their errors from spec-thrown 
errors, and then do

```js
try {
  someOperation();
} catch (e) {
  if (!e.crossLibraryStandardFlagForLibraryThrownNotSpecThrown) {
    throw e;
  }
  handleOperationalError(e);
}
```

which as per previous complaints on this thread also has the problem that you 
lose stack trace information.
    
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to