Is there any way to catch the `KeyNotFoundException` in Java `HashMap` and add the key to the map in catch block? 

For example, I want to add a value to the key in `HashMap`. If that key is not present, then `KeyNotFoundException` will be thrown. 

One alternative is to each time check if the key exists. If it doesn't, add the key and then add the value. If it exists, directly add the value to the key. However, there will be lots of overhead with the if conditions. So, when this exception is thrown, can I add the key and value in the catch clause and then proceed properly?