pub fn is_error(catched: K) -> bool
Expand description
Judge if a catched object by error_to_string
is a genuine error object of type
qtype::ERROR
(This means false positive of the KNULL
case can be eliminated).
§Examples
use kdbplus::*;
use kdbplus::api::*;
fn love_even(arg: K) -> K{
if let Ok(int) = arg.get_int(){
if int % 2 == 0{
// Silent for even value
KNULL
}
else{
// Shout against odd value
new_error("great is the even value!!\0")
}
}
else{
// Pass through
increment_reference_count(arg)
}
}
#[no_mangle]
pub extern "C" fn propagate(arg: K) -> K{
let result=error_to_string(love_even(arg));
if is_error(result){
// Propagate the error
result
}
else if result.get_type() == qtype::ERROR{
// KNULL
println!("this is KNULL");
decrement_reference_count(result);
KNULL
}
else{
// Other
new_symbol("sonomama")
}
}
q)convey: `libapi_examples 2: (`propagate; 1);
q)convey[7i]
'great is the even value!!
q)convey[12i]
this is KNULL
q)convey[5.5]
`sonomama
§Note
In this example KNULL
is used as a returned value of the function called by another function to demonstrate
how is_error
works. However, KNULL
should not be used in such a way in order to avoid this kind of complexity.
To return a general null for inner functions, use new_null
instead.