From cd4a999e80ba624c7314e72cfa72892c91c7a46c Mon Sep 17 00:00:00 2001 From: Mykhailo <56037377+hidalgo-vntu@users.noreply.github.com> Date: Mon, 31 Oct 2022 09:56:41 +0200 Subject: [PATCH] examples: add custom_error.v, that shows how to match over possible errors (#16265) --- examples/custom_error.v | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 examples/custom_error.v diff --git a/examples/custom_error.v b/examples/custom_error.v new file mode 100644 index 000000000..e763fcfd0 --- /dev/null +++ b/examples/custom_error.v @@ -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') + } + } +} -- 2.30.2