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:
parent
0390a7a988
commit
cd4a999e80
20
examples/custom_error.v
Normal file
20
examples/custom_error.v
Normal 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')
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user