I want to try to catch panic for a async function which looks like below:
let x = a_sync_function(param1, param2).await?;
// the return of `a_sync_function` is : Result<Vec<serde_json::Value>, Box<dyn Error>>
if there is any panic when above code running, I want to catch the panic and run another code; how shall I do this?
catch_unwind()doesn't take a future, so you cannot use it.Luckily,
futureshasFutureExt::catch_unwind(), that wraps a future with panic catching. Under the hood, it usescatch_unwind()for everypoll().