In the below code, I'm trying to try-catch.
try-catch Function:
const updateReturnInformation = async () => {
if (state.isLoading) {
throw new Error('Errrrrror!!!') // <- It is success working
}
dispatch(actionSetLoading(true))
try {
await updateReturnAPI(...)
} catch (ex) {
return ex // <- why not working?
} finally {
dispatch(actionSetLoading(false))
}
}
And, I called this function in another component:
...
try {
await updateReturnInformation()
navigation.navigate(Routes.Root.Modal.Confirm, {
title: 'success!',
buttons: ['OK'],
})
} catch (ex) {
navigation.navigate(Routes.Root.Modal.Confirm, {
heading: 'Error',
title: ex,
buttons: ['OK'],
})
}
...
I called updateReturnInformation(), But It working only print 'success!' message.
Also, The console.log will still only print a 'success!' message if an error occurs.
Changing the return error of updateReturnInformation () to throw error works fine, but I have to only use return error.
What's wrong?
updateReturnInformation()to anything. How can you tell thatreturn exis not working?