tryCatch should work with nAry arguments
See original GitHub issueCurrently, tryCatch
always returns unary functions even if the input passed to it is nAry.
We can change this behaviour with the proposed implementation, if this doesn’t cause any breaking problems.
const tryCatch = function tryCatch(fn) {
if(!isFunction(fn)) {
throw new TypeError('tryCatch: Function required for first argument')
}
const safe = function() {
try { return Ok(fn.apply(this, arguments)) }
catch(e) { return Err(e) }
}
Object.defineProperty(safe, "length", { value: fn.length })
return safe
}
const add = tryCatch((a, b) => {
return a + b
})
add(1, 2) => 3
curry(add)(1)(2) => 3
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
When to use Try/Catch? - webMethods
I'm sometimes asked to assess the quality of work performed by other consulting firms. When I find massive numbers of Flow services with...
Read more >How do you make tryCatch actually catch the error
You can pass a function to the error argument of tryCatch to specify what should happen when there is an error. In this...
Read more >kdb+/q - Try Catch - Java Code Geeks - 2022
g – a function to execute if f fails. This function is called with two arguments, the error string x and the backtrace...
Read more >Using tryCatch Function to Handle Errors & Warnings in R (3 ...
Within the tryCatch function, we usually should specify four arguments: expr: This specifies the expression we want to evaluate. error: The message we...
Read more >How to Apply Try Catch Block in PHP - Linux Hint
The script will take two numeric values from the URL query parameters and the try-catch block will call a function that will throw...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t see problems with the
defineProperty
itself, but the spread operator is going to destroy context. Edited to use the old-school way.Shipped with 0.11.0