Ad
  • Custom User Avatar

    Not really though. You are wrapping code that will only break because of the break exception (no possible other reason could make it fail), then catching that exception that you know will be thrown, and then doing nothing with it.

    if (iterator(val)){
        try {
            res = index; // this has no purpose
            throw BreakException; // this is the only possible thing that will throw
        } catch (e){
            // e will only ever be BreakException, never anything else
            if (e!==BreakException) { throw e; }
           // e was trapped so nothing actually happens due to it being thrown
        }
    }
    
    
  • Custom User Avatar

    I fixed the description to say value instead of v.

    Not quit sure whats being asked here since the code is printed out a bit funny. Why are you purposely throwing an exception just so that you can catch it?