Created
December 24, 2019 10:35
-
-
Save MaryamZi/2af573d67b702ee69e216fb7d17a78de to your computer and use it in GitHub Desktop.
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
import ballerina/io; | |
const REASON = "ErrorReason"; | |
type Detail record {| | |
string message; | |
error cause?; | |
int code; | |
|}; | |
type CustomError error<REASON, Detail>; | |
public function main() { | |
// Use the direct error constructor to create an error | |
// similar to what could be created as a `CustomError`. | |
error err = error("ErrorReason", | |
message = "error message", | |
code = 1122); | |
// Since the error value is immutable it cannot be changed | |
// now. The type test evaluates to `true` since the reason is | |
// the same as what is expected by `CustomError` and the expected | |
// detail fields (i.e., `message`, `code`) are also available | |
// and are of the expected types. | |
io:println(err is CustomError); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment