The rules governing chess are the FIDE Laws of Chess. This point is explicitly covered in Article 3: The moves of the pieces
3.9.2 No piece can be moved that will either expose the king of the same colour to check or leave that king in check.
The move f3 violates this rule because it exposes the king to check. As such it is an illegal move. Your program should not allow illegal moves so should not allow this move in just the same way that you do not allow the pawn to move from f2 to f5 in one move.
In a real game when an illegal move is made the move must be taken back and a legal move made in its place. In competition chess there are also penalties for making illegal moves.