# catch Error

**URL:** <https://es.discourse.group/t/catch-error/904>\
**Category:** 💡 Ideas\
**Created:** [August 7, 2021, 4:10am UTC](https://es.discourse.group/t/catch-error/904 "2021-08-07T04:10:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [August 7, 2021, 4:24am UTC](https://es.discourse.group/t/catch-error/904/2 "2021-08-07T04:24:41Z")

</div>

Interesting idea. This sounds like an issue that could potentially be solved in a more general purpose way. For example, I know it's common for a function that expects a string to take whatever parameter it recieves and coerce it into a string, as a first step, like this:

```javascript
function concat(x_, y_) {
  const x = String(x_)
  const y = String(y_)
  return x + y
}

```

What if, at _any_ location where you're binding a value to a variable, you're allowed to pass the incomming value through a normalization function first, through, say, a "from" keyword (I don't like this "from" word - feel free to bikeshed it). That would make the above example equivalent to this:

```javascript
function concat(x from String, y from String) {
  return x + y
}

```

It would also allow you to automatically coerce an unknown value to an error.

```javascript
try {
  foo();
} catch (e from Error) {
  console.log(e.stack);
}

// ... is the same as ...

try {
  foo();
} catch (e_) {
  let e = Error(e_)
  console.log(e.stack);
}

```

Some more usage examples :

```javascript
const normalizedDegrees = deg => deg % 360

function toRadians(deg from normalizedDegrees) {
  // ...
}

```

```javascript
const positiveNumberAssertion = value => {
  if (value <= 0) throw new Error('Whoops!')
  return value
}

function doOperation(x from positiveNumberAssertion) {
  // ...
}

```

```javascript
const {
  index from i => i + 1,
  ...otherParams
} = data

```

---

_[View the full topic](https://es.discourse.group/t/catch-error/904)._
