Is a JavaScript try-catch ignoring an expected occasional error bad practice?
问题 In JavaScript is it wrong to use a try-catch block and ignore the error rather than test many attributes in the block for null? try{ if(myInfo.person.name == newInfo.person.name && myInfo.person.address.street == newInfo.person.address.street && myInfo.person.address.zip == newInfo.person.address.zip) { this.setAddress(newInfo); } } catch(e) {} // ignore missing args 回答1: If you expect a particular condition, your code will be easier to maintain if you explicitly test for it. I would write