Validating possibilities for HasMap access : Im asking myself what could be the more elegant way of validating a HasMap access.

    Map<String, String> m = new HashMap<>();

    if(m.hasNext()){
        ...}
    else
        System.out.println("Error.");

or

    Map<String, String> m = new HashMap<>();
    
    try{
        m.getNext();
    catch(Exception e){
            ...}