Why Is This Try Catch Not Working - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Why Is This Try Catch Not Working (672 Views)
| Why Is This Try Catch Not Working by chukwuebuka65(op): 10:04pm On Aug 20, 2023 |
.
|
| Re: Why Is This Try Catch Not Working by richebony: 10:34pm On Aug 20, 2023 |
I think set timeout() is asynchronous and registers an event that is handled by the libuv . Place another try-catch inside your setTimeout async block |
| Re: Why Is This Try Catch Not Working by Paystack(f): 10:37pm On Aug 20, 2023 |
It is working exactly as it should... you're sending a message but nowhere to receive it. You need to add Onmessage listener in your contentScript, PopUp or the Background itself |
| Re: Why Is This Try Catch Not Working by chukwuebuka65(op): 10:42pm On Aug 20, 2023 |
Paystack:Are you even a developer? What then is the purpose of a try catch block? |
| Re: Why Is This Try Catch Not Working by Paystack(f): 10:48pm On Aug 20, 2023 |
chukwuebuka65:You asked it to console the error which it is clearly doing. I'm not a developer ![]() The block tried your faulty code it didn't work It then catch it and spilled the trash out to u |
| Re: Why Is This Try Catch Not Working by chukwuebuka65(op): 10:49pm On Aug 20, 2023 |
Paystack:That’s not the issue. I know why the error is happening . My question is why the catch block is not catching the error and logging it to the console. |
| Re: Why Is This Try Catch Not Working by chukwuebuka65(op): 10:50pm On Aug 20, 2023 |
. |
| Re: Why Is This Try Catch Not Working by chukwuebuka65(op): 11:00pm On Aug 20, 2023 |
Paystack:The second pics is not the console, it’s the extension management tab. The console is empty |
| Re: Why Is This Try Catch Not Working by chukwuebuka65(op): 11:11pm On Aug 20, 2023 |
richebony:This worked. But why ? |
| Re: Why Is This Try Catch Not Working by richebony: 12:23am On Aug 21, 2023 |
chukwuebuka65:I think I explained in the preceding text, the setTimeout function is asynchronous and isn't a native js function, and your callback function is invoked on a different execution context because its the libuv [c++] APIs that nodejs delegates the timer function to. So your try-catch block isn't bound to your callback function because it exists in a different execution context |
| Re: Why Is This Try Catch Not Working by Paystack(f): 1:55am On Aug 21, 2023 |
richebony:Nice |
| Re: Why Is This Try Catch Not Working by chukwuebuka65(op): 8:10am On Aug 21, 2023 |
richebony:Ok makes sense. Thanks |
| Re: Why Is This Try Catch Not Working by qtguru(m): 8:46am On Aug 21, 2023 |
rich-ebony is correct in a way, but also you're sending a post-message, the source isn't sure whether to close it or not, because it is not informed of what to do, from the onMessage handler you send a sendResponse back so that it will close. That is the Chrome extension architecture around post-messaging. try it, i faced alot of that too |
| Re: Why Is This Try Catch Not Working by chukwuebuka65(op): 9:19am On Aug 21, 2023 |
qtguru:Alright boss. |
Want To Learn Devops? The Free Resources Are Great, But Here's The Catch! • Whatsapp's Struggles To Catch Up With Telegram And Outshine Them • 2 • 3 • 4
After Contract, WHAT NEXT? • Help All Programmer Enter please enter • And The Dodgers' 290 Home Average Is Near The Top Of The Majors
