{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"redocly_category":"Journeys","product":"Identity Management","type":"markdown"},"seo":{"title":"Expressions: Try expressions","description":"Everything about Mosaic Journeys, SDKs, and APIs","siteUrl":"https://developer.transmitsecurity.com/","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"expressions-try-expressions","__idx":0},"children":["Expressions: Try expressions"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"_","__idx":1},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["An expression's evaluation may return an error—for example, when trying to divide a number by zero, or when a network call fails. Typically, an expression returning an error will result in failing the journey in the context in which it is executed. Try-expressions allow recovering from errors in expressions, possibly providing an alternate value for the result."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The syntax for a try-expression is as follows:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"js","header":{"controls":{"copy":{}}},"source":"try body catch alternate\n","lang":"js"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["where ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["body"]}," is the expression to evaluate and guard from errors, and ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["alternate"]}," is the alternate value to return in case of an error. If the evaluation of body completes successfully, its return will be the return value of the try-expression. Otherwise, the returned value will be the result of evaluating alternate."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Consider these examples. For ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["try 3/2 catch 10"]},", the guarded expression here ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["(3/2)"]}," doesn't yield any error on evaluation so the try-expression returns its result (1.5). However, for ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["try 3/0 catch 10"]},", the guarded expression results in an error (division by zero), so the value of the alternate expression (10) will be returned."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If the alternate expression is a lambda, the try-expression behavior changes slightly. Instead of returning the alternate itself (which would be of a lambda type), the alternate will be invoked with a single parameter which is a description of the error that occurred; it is the return value of this invocation that will be returned from the try-expression."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Consider this example: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["try 3/0 catch (error)=>\"Encountered an error: \" + error"]},". The return value would be the result of invoking the lambda ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["(error)=>\"Encountered an error: \" + error"]}," with the error description as its single argument. So the overall return from this try-expression will be the string ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["\"Encountered an error: TSError: expression.arithmetic_error:[Division by zero]\""]},"."]}]},"headings":[{"value":"Expressions: Try expressions","id":"expressions-try-expressions","depth":1},{"value":"","id":"_","depth":2}],"frontmatter":{"showNextButton":true,"showPrevButton":true,"seo":{"title":"Expressions: Try expressions"}},"lastModified":"2025-11-18T16:48:04.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/guides/orchestration/getting-started/expressions/try","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}