stateful exception-handling

stateful exception-handling

The idea is to give the programmer an attempt to (real-time) patch the code

Original


try {
    let b = 5
    let c = 6
    let sum = b0 + c0 /* Generates : reference error - b0 not defined, reference error - c0 not defined, warning - b declared but never used, warning - c declared but never used */
} catch (e) {
   // no chance here to re-evaluate original code! // 
}

Version 2


onThreadError {
    let b = 5
    let c = 6
    let sum = b0 + c0
} try(e,a) {
    /*
        e = { 
            "reference error" : [
                { variable : b0, error : "not defined" },
                { variable : c0, error : "not defined" },
                ],
            "warning" : [
                { variable : b, error : "declared but never used" },
                { variable : c, error : "declared but never used" },
                ],
                },            
        a = {
            statement : [
                { index : ['let','b','=','5'] },
                { index : ['let','c','=','6'] },
                { index : ['let','sum','=','b0','+','c0'] }, 
                ]   
                }                
    */
    if(e){
        // attempt a patch (indefinitely, while or until if(e) conditions are met)//
        a.statement[0].index[1] = 'b0'
        a.statement[1].index[1] = 'c0'
    } else {
        // revert to traditional catch (handler) //
        .
        .
        .
        continue
    }
}

If you know that the code is patchable, why wouldn't you edit the code beforehand?

In other words, this is the sort of trivial issue a linter catches at "build time", so I'm very confused why it would make sense to add complexity to "run time" to handle it.

3 Likes