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 MY_REASON = "MyReason"; | |
type MyDetail record {| | |
string message; | |
error cause?; | |
int code?; | |
boolean|float...; | |
|}; |
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 MY_REASON = "MyReason"; | |
type MyDetail record {| | |
string message; | |
error cause?; | |
int code?; | |
anydata|error...; | |
|}; |
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; | |
function foo() returns error? { | |
return error("ErrReason", message = "err message", code = 123, bar = 45.6, baz = false); | |
} | |
public function main() { | |
error? res = foo(); | |
if res is error { |
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 MY_REASON = "MyReason"; | |
type MyDetail record {| | |
string message; | |
error cause?; | |
int code?; | |
anydata|error...; | |
|}; |
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; | |
function foo() returns error? { | |
return error("ErrReason", message = "err message", code = 123); | |
} | |
public function main() { | |
// Say I call a function returning either an `error` or `()`. | |
error? res = foo(); |
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; | |
|}; |
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
public function main() { | |
error err = error("TestError", | |
message = "error message", | |
code = 1111); | |
record {| | |
string message?; | |
error cause?; | |
anydata|error...; | |
|} detail = err.detail(); |
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/log; | |
const ERR_REASON_FILE_NOT_FOUND = "FileNotFound"; | |
const ERR_REASON_INSUFFICIENT_PERMISSION = "InsufficientPermission"; | |
// The detail type for `FileNotFoundError` defaults to the default detail type now. | |
type FileNotFoundError error<ERR_REASON_FILE_NOT_FOUND>; | |
type ErrDetail record {| | |
string message?; |
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() { | |
xmlns "http://abc.def"; | |
xml x = xml `<hello foo="bar"> | |
<ns1:world xmlns:ns1="http://qwe.asd" xyz="pqr">hello world</ns1:world> | |
</hello>`; | |
io:println(x); |
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. |
NewerOlder