You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exceptions, try-catch[-finally] and try-finally patterns are not functional.
I would like to propose adding 1 or 2 new rules to prevent the use of these.
Below are some examples on how to switch out use of throw and try-catch.
Original code for examples:
constnumbers=[[4,2],[6,0],[3,4]];try{doDivide(numbers).forEach((result)=>{console.log(result);});}catch(error){console.error(error.message);}functiondoDivide(numbers: number[][]): number[]{returnnumbers.map(([x,y])=>divide(x,y));}functiondivide(x: number,y: number): number{if(y===0){thrownewError('Cannot divide by zero.')}returnx/y;}
Exceptions, try-catch[-finally] and try-finally patterns are not functional.
I would like to propose adding 1 or 2 new rules to prevent the use of these.
Below are some examples on how to switch out use of
throw
andtry-catch
.Original code for examples:
Example - Returning an error:
Example - Returning a rejected promise:
(Should only be used with async code)
The text was updated successfully, but these errors were encountered: