E1026#
The patterns are complete so the usage of catch!
is useless. In MoonBit, when
there is only one error type that will be raised in a try block, compiler will
know that the error type is the only one that will be caught. So, there is no
need to use catch!
in this case.
Erroneous example#
type! E
fn f() -> Unit!E {
raise E
}
fn g() -> Unit! {
try {
f!()
} catch! {
E => raise E
}
}
fn main {
try {
g!()
} catch {
_ => println("Error")
}
}
Suggestion#
Remove the !
in the catch!
:
type! E
fn f() -> Unit!E {
raise E
}
fn g() -> Unit! {
try {
f!()
} catch {
E => raise E
}
}
fn main {
try {
g!()
} catch {
_ => println("Error")
}
}