Exception handling for infinite loop
Ysajid opened this issue · 8 comments
লুপ( অসীম বার) {
দেখাও("ঘুরছে")
}
if this code is run the browser freezes and gives a prompt to stop the script
yes it does, its usual for many languages like C, Javascript etc.
Yes, but online IDEs handle this by giving runtime error.
Can't it be implemented?
why not. We are very busy to build the core features. Could you make a script to handle javascript infinit loop?
True. Keep up the good work 👍
I will get back if i can make the script
closing the issue for now.
@Ysajid Interesting point. I am not sure if this is going to be helpful but, with my very limited knowledge in Javascript, I think it is single threaded meaning that one thread handles your event loop. I am not sure if you can stop an infinite loop after its execution starts. If you try similar infinite loop written in javascript, in other online javascript compiler (such as JSFiddle, js.do etc.) your browser will freeze just like it does with potaka.io . For example. try this example: http://js.do/code/106546
Also noticed something in the debugger (in SCRIPT0:2) after running your code in potaka.io :
for (let _ইন্ডেক্স = 1; _ইন্ডেক্স <= 1e+400; _ইন্ডেক্স++) {
দেখাও('\u0998\u09c1\u09b0\u099b\u09c7');
}
I guess we could change the default 1e+400 to some number so that the browser does not freeze. But we definitely should NOT implement that. Not an option 🐱
Also take a look at this stackoverflow question I posted and its answers. Might give you some clue.
Good luck figuring out the solution. It will be a cool feature. 😺
I found exactly what I was looking for. If you run this piece of code in an online compiler, your browser will freeze for 5 seconds then you will get an alert saying, "Taking taking longer than 5 seconds to execute so it was killed."
function infiniteLoop() {
dateAtStartOfExecution = Date.now();
while(true) {
//do something
document.getElementById("someID").innerHTML = "Blah";
if (Date.now() > dateAtStartOfExecution+5000) {
alert("Taking taking longer than 5 seconds to execute so it was killed.");
return;
}
}
}
Try this: http://js.do/code/106565
Nice, very neat solution 👍
@dhrubomoy Thanks for the solution. It's implemented