I tried to create a game where the object simply looks in the direction of the mouse. Therefore, I used the coordinates of mouseInfo and just put it into a turnTowards()-method. Once I started the programm, I got a NullPointerException. I put the method in a try/catch block, because I thought, it only occured in the first frame, and it works. But when I printed the exception I figured out it called it every frame.
I just wonder why it works, since there is only a single line of code, where the exception has to be thrown, and that should mean, that it was not exectuted(?)
My Code:
I´d be happy if someone understanding me could teach me why it works;-)
public void aim(){
try{
turnTowards(Greenfoot.getMouseInfo().getX(), Greenfoot.getMouseInfo().getY());
}
catch(Exception e){}
}

