1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples: add custom_error.v, that shows how to match over possible errors (#16265)

This commit is contained in:
Mykhailo 2022-10-31 09:56:41 +02:00 committed by GitHub
parent 0390a7a988
commit cd4a999e80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

20
examples/custom_error.v Normal file
View File

@ -0,0 +1,20 @@
import semver
fn main() {
semver.from('asd') or { check_error(err) }
semver.from('') or { check_error(err) }
}
fn check_error(err IError) {
match err {
semver.InvalidVersionFormatError {
println('wrong format')
}
semver.EmptyInputError {
println('empty input')
}
else {
println('unknown error')
}
}
}