Question: While a `HashMap` item can be deleted, or user may input a key that doesn not exist in `HashMap`, what kind of `Try/Catch` block should I add for `.get()` method ?

Here's my code example :

```
public class ProjectModel {

    private int size = 0;
    private Project[] projects = new Project[100];
    private HashMap<Integer, Integer> index = new HashMap<Integer, Integer>();

    public Project create(){

        Project project = new Project();
        int id = project.getId();
        projects[size] = project;
        index.put(id, size);        
        size++;     
        return project;

    }

    public Project select(int id){

        int i = index.get(id); //<----- get method here
        Project project = projects[i];
        return project;

    }

    public void delete(int id){

        int i = index.get(id);      
        projects[i] = null;
        index.remove(id);

    }

}

```

---

additional note :
I ask this because I don't want user select a item that is not exists.
Like there is 5 item, but I try to ProjectModel.select(6);
Whenever HashMap.get() return null, I want to handle it (In my mind it's a Exception to the flow).

Edit :

I have read the comments to the answers, thank you. While I am new to Java, please let me know if I got the idea correct or not, please tell me at the comment.

1. It's ok for return null from a "object selecting function"
2. Instead to throw Exception inside this unit, it is better to do the error handle where I call ProjectModel.select().

Answer: 
You don't need a try/catch block; `HashMap.get` will return `null` on an absent key, as specified in its Javadoc.

> 
> Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
> 
> 
>
You really don't need to use `try/catch` for `get` method of `HashMap` because it doesn't throws any exception, **BUT** you can mark the `create`, `select` and `delete` methods as `throws custom exception` when id not found or `index.get(id)` be null:

```
public void delete(int id) throws SomeCustomException {
    if (index.get(id) == null) {
        throw new SomeCustomException("No such element exists");
    }
    int i = index.get(id);
    projects[i] = null;
    index.remove(id);
}

```