-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Maryam Ziyad <[email protected]>
- Loading branch information
1 parent
9db9dcf
commit 76d3d05
Showing
10 changed files
with
77 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
# Check expression | ||
|
||
In Ballerina, it is common to write an expression that may result in an error, such as calling a function that could return an error value, checking if the result belongs to the `error` type and immediately returning that value. You can use the `check` expression to simplify this pattern. | ||
If an expression can cause an `error`, you can use the `check` expression to indicate you want to terminate the execution of the current scope with that error as the result. Generally this is done by returning the error value from the current function. | ||
|
||
::: code check_expression.bal ::: | ||
|
||
::: out check_expression.out ::: | ||
|
||
+ [`check` semantics](https://ballerina.io/learn/concurrency/#check-semantics) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
$ bal run check_expression.bal | ||
error("{ballerina/lang.int}NumberParsingError",message="'string' value 'hello' cannot be converted to 'int'") | ||
error("{ballerina/lang.int}NumberParsingError",message="'string' value 'hello' cannot be converted to 'int'") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
$ bal run error_reporting.bal | ||
message: failed to parse digit | ||
details {"stringValue":"1x3"} | ||
stack trace: [callableName: parseInt fileName: error_reporting.bal lineNumber: 14,callableName: main fileName: error_reporting.bal lineNumber: 62] | ||
cause: error("unexpected char for digit value",charValue="x") | ||
message: unexpected char for digit value | ||
details {"charValue":"x"} | ||
stack trace: [callableName: parseDigit fileName: error_reporting.bal lineNumber: 56,callableName: parseInt fileName: error_reporting.bal lineNumber: 10,callableName: main fileName: error_reporting.bal lineNumber: 62] | ||
message: failed to validate people | ||
details: {"people":[{"name":"Alice","age":25},{"name":"Bob","age":-1}]} | ||
stack trace: [callableName: validatePeople fileName: error_reporting.bal lineNumber: 12,callableName: main fileName: error_reporting.bal lineNumber: 28] | ||
cause: | ||
message: age cannot be negative | ||
details: {"person":{"name":"Bob","age":-1}} | ||
stack trace: [callableName: validatePerson fileName: error_reporting.bal lineNumber: 19,callableName: validatePeople fileName: error_reporting.bal lineNumber: 10,callableName: main fileName: error_reporting.bal lineNumber: 28] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
# Type intersection for error types | ||
|
||
If you intersect two `error` types, the resulting type's detail type is the intersection of the detail types of both types. Furthermore, if any of the types being intersected is a distinct type, then the resultant type's type ID set includes all the type IDs of that type. | ||
If you intersect two `error` types, the resulting type's detail type is the intersection of the detail types of both types. Furthermore, if any of the types being intersected is a distinct type, then the resultant type's type ID set includes all the type IDs of that type. Thus it is a subtype of both types and this is how you create subtypes of `distinct` error types. | ||
|
||
::: code error_type_intersection.bal ::: | ||
|
||
::: out error_type_intersection.out ::: | ||
|
||
+ [Error subtyping](https://ballerina.io/learn/by-example/error-subtyping/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters