Skip to content

Commit f5771e7

Browse files
committed
a small mint
1 parent 3310b1f commit f5771e7

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

powerapps-docs/maker/canvas-apps/functions/function-iferror.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,44 @@ Detects errors and provides an alternative value or takes action.
2121
> [!NOTE]
2222
> This function is part of an experimental feature and is subject to change. The behavior described here is only available when the *Formula-level error management* feature is turned on. This is an app level setting that defaults to off. To turn this feature on, navigate to the *File* tab, *App settings* in the left hand menu, and then *Experimental features*. Your feedback is very valuable to us - please let us know what you think in the [PowerApps community forums](https://powerusers.microsoft.com/t5/Expressions-and-Formulas/bd-p/How-To).
2323
24-
The **IfError** function tests each of its arguments in order for an error value, stopping when the first non-error value is found. The arguments after the non-error value is found are ignored and not evaluated.
24+
The **IfError** function tests one or more values until an error result is found. If an error is found, a corresponding value is returned. If no error is found, a default value is returned. In either case, the returned value might be a string to show, a formula to evaluate, or another form of result. The **IfError** function is very similar to the **If** function: **IfError** tests for errors, while **If** tests for **true**.
2525

26-
Use **IfError** to replace error values with a valid value. For example, if it is possible that user input may result in a division by zero, replace it with a 0 or other valid value that is appropriate for your app so that downstream calculations can proceed.
26+
Use **IfError** to replace error values with a valid value. For example, if it is possible that user input may result in a division by zero, replace it with a 0 or other valid value that is appropriate for your app so that downstream calculations can proceed. For example, a simple pattern is:
2727

28-
Use **IfError** in [behavior formulas](../working-with-formulas-in-depth.md) to perform actions, check the results for errors, and if needed take further actions or display an error message to the user with [**Notify**](function-showerror.md).
28+
```powerapps-dot
29+
IfError( 1/x, 0 )
30+
```
2931

30-
If all of the arguments to **IfError** result in an error, the value of the last argument is returned (which will be an error value).
32+
If the value of **x** is non-zero, the formula will return **1/x**. However, if **x** is zero, **1/x** will result in an error, and **IfError** will return 0 instead.
33+
34+
Use **IfError** in [behavior formulas](../working-with-formulas-in-depth.md) to perform an action and check for an error before continuing to perform additional actions. For example in this pattern:
35+
36+
```powerapps-dot
37+
IfError(
38+
Patch( DS1, ... ), Notify( "problem in the first action" ),
39+
Patch( DS2, ... ), Notify( "problem in the second action" )
40+
)
41+
```
42+
43+
If there is a problem with the **Patch( DS1, ... )** then the first **Notify** will execute and no further processing will occur and **Patch( DS2, ... )** will not happen. But if **Patch( DS1, ... )** succeeds then the second patch will happen, and the second **Notify** executed if there is a problem with it.
44+
45+
If no errors are found, the value of the optional *DefaultResult* is returned. If that argument is not provided, the value of the last *Value* argument evaluated is returned.
3146

3247
## Syntax
33-
**IfError**( *Value*, *Fallback1* [, *Fallback2*, ... ] )
48+
**IfError**( *Value1*, *Fallback1* [, *Value2*, *Fallback2*, ... [, *DefaultResult* ] ] )
3449

35-
* *Value* - Required. Formula(s) to test for an error value.
36-
* *Fallback(s)* - Required. The formulas to evaluate and values to return if previous arguments returned an error. *Fallback* arguments are evaluated in order up to the point a non-error value is found.
50+
* *Value(s)* - Required. Formula(s) to test for an error value.
51+
* *Fallback(s)* - Required. The formulas to evaluate and values to return if matching *Value* arguments returned an error.
52+
* *DefaultResult* - Optional. The formulas to evaluate if no errors were found.
3753

3854
## Examples
3955

4056
| Formula | Description | Result |
4157
| --- | --- | --- |
42-
| **IfError( 1, 2 )** |The first argument is not an error. It is returned and subsequent arguments are not evaluated. | 1 |
43-
| **IfError( 1/0, 2 )** | The first argument is returning an error value (due to division by zero). The second argument is evaluated resulting in a non-error value which is returned. | 2 |
58+
| **IfError( 1, 2 )** |The first argument is not an error. There are no other errors to check and no default return value was provided. The formula returns the last *value* argument evaluated. | 1 |
59+
| **IfError( 1/0, 2 )** | The first argument is returning an error value (due to division by zero). The second argument is evaluated and returned as the result. | 2 |
4460
| **IfError( 1/0, Notify( "There was an internal problem", NotificationType.Error ) )** | The first argument is returning an error value (due to division by zero). The second argument is evaluated which displays a messages to the user. The return value of **IfError** is the return value of **Notify**, coerced to the same type as the first argument to **IfError** (a number). | 1 |
45-
| **IfError( 1/0, 1/0, 2, 1/0, 3 )** | The first argument is returning an error value (due to division by zero). The second argument is evaluated, also resulting in an error value (another division by zero). The third argument is evaluated, which does not return in an error value which is returned. The fourth and fifth arguments are ignored. | 2 |
61+
| **IfError( 1, 2, 3, 4, 5 )** | The first argument is not returning an error, so its corresponding fallback is not evaluated. The third argument is not return an error either, so its corresponding fallback is not evaluated. The fifth argument has no corresponding fallback and is the default result which is returned since no errors were found. | 5 |
4662

4763
### Step by step
4864

0 commit comments

Comments
 (0)