A helper that wraps a risky function. The new function runs the tryer; if the tryer throws, it runs the catcher and returns that result instead — a try...catch block packaged as a reusable function.
Status: stable since Ramda v0.20.0 — not deprecated, experimental, or non-standard.
Syntax
Call R.tryCatch. Start with this line.
Ramda
R.tryCatch(tryer, catcher)
Call
What it does
R.tryCatch(tryer, catcher)
Primary signature.
R.tryCatch(...)
Call the function helper.
Prefer import { tryCatch } from "ramda" when you want a named import.
Library declarations
Ramda
R.tryCatch(tryer, catcher)
Parameters
Parameter
Description
tryer
Required. The function that may throw
catcher
Required. Called as catcher(err, ...args) only when tryer throws
Return Value
Return Value
Description
*
A new function that takes the same arguments as tryer
Result. Valid JSON → 3; bad JSON → {} → 0. No crash either way.
Compatibility
Browser & Runtime Support
R.tryCatch has been in Ramda since v0.20.0. Ramda’s browser build is plain ES5, so it runs in any modern browser and in Node.js / Bun / Deno with npm install ramda.
✓ Stable · Ramda 0.20.0+
R.tryCatch()
Built on JavaScript’s own try...catch, so no special browser API is needed. The examples use ES2015 arrow functions, supported by every evergreen browser.
100%With Ramda 0.20.0+
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
R.tryCatchRamda 0.20.0+
Bottom line: Safe for production with Ramda 0.20.0 or newer. Remember it handles synchronous throws only. The labs on this page use [email protected].
Frequently Asked Questions
R.tryCatch(tryer, catcher) returns a new function. It runs tryer with your arguments; if tryer returns normally, you get that result. If tryer throws, catcher runs instead and its return value is the result. Docs sample: R.tryCatch(R.prop('x'), R.F)({ x: true }) //=> true.
A try...catch block is a statement you write in place. R.tryCatch builds a reusable function, so you can name it, pass it around, and drop it straight into R.pipe or R.map.
The error first, then every original argument: catcher(err, ...args). That lets a catcher log the error and still use the input, e.g. (err, value) => ({ error: err, value }).
No. It only catches errors thrown synchronously. An async tryer returns a Promise, and if that Promise rejects, the catcher is never called. Use R.otherwise or .catch() for Promises.
The Ramda docs say both should return the same type for effective composition. If success gives an object and failure gives {}, the next pipe step can handle both without extra checks.
No. R.tryCatch has been a stable Ramda function helper since v0.20.0 — not deprecated, experimental, or non-standard.