Last active
September 28, 2019 09:25
-
-
Save MaryamZi/3600982b589ec1c17a5f39006077ee15 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; | |
public function main() { | |
// If `foo()` does not panic, x will hold | |
// the value returned by `foo()` | |
int|string|error x = foo(1); | |
io:println(x); | |
// If `foo()` panics, x will hold | |
// the error associated with the panic. | |
x = trap foo(3); | |
io:println(x); | |
io:println("Done"); | |
} | |
function foo(int i) returns int|string { | |
match i { | |
1 => { | |
return 1; | |
} | |
2 => { | |
return "two"; | |
} | |
_ => { | |
panic error("not one or two"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment