I'm going through a beginner programming learning guides and the teacher brings up the try catch block paradigm.
The code you put in the try block is run and if an error happens the code in the catch block is run. Your application should recover from it.
try {
// do something that might throw an error
}
catch (exceptionError) {
// handle when it happens
}
I see this working where an application to recover.
Is there paradigm where you can say,
Run this fragment of code but if it doesn't respond in this set amount of time throw an error?
try(10000) {
// do something that only has a certain amount of time to execute
}
catch (error) {
log("Task error:"+error);
}
timeout (error) {
log("Process took too much time");
}
For example,
// give code block ten seconds to error or execute
try(10000) {
var numberOfTimes = 10,000,000;
for (var i=0;i<numberOfTimes;i++) {
drawPolygon(i);
renderCount++;
}
log("Total number of polygons rendered:"+renderCount);
}
timeout(error) {
log("Total number of polygons rendered:"+renderCount);
}
catch(error) {
log("Error")
}
I made this example off the top of my head. It's not about the example it's about if this language design feature exists.
timeout
-type library call out of the underlying syscalls.