Cannot implement auto topup functionality

I tried to implement auto top-up functionality on dynamically created canisters by catching the exception using try-catch block. But I get the following error and cannot call any function inside the canister
Canister emgws-yyaaa-aaaai-qh7ta-cai is out of cycles: requested 2000590000 cycles but the available balance is 3645270775 cycles and the freezing threshold 1658809665 cycles
Why am I getting this error?
Is there any better way to do the same thing?