Can someone please explain to me what is the difference between an event handler and a callback function?
An event handler is a type of callback. It's called whenever an event occurs. The term is usually used in terms of user interfaces where events are things like moving the mouse, clicking something and so on.
A callback is procedure you pass as an argument to another procedure. The procedure receiving the parameter can call it, or share it so some other procedures in the system can call it.
An event handler is a procedure called when an event happens. It can be a callback.
Generally speaking a 'callback' is under the controll of the detecting process. So you tell a GUI manager "call myaction when this button is pressed" and the GUI manager calls the action when the button is pressed.
Event Handlers on the other hand operate at one step removed. The GUI manager is configured to send messages to an event handler. You tell an event manager that button pushes are handled by the 'myaction' program. When the button is pushed the GUI manager puts a message on the event handlers queue and gets on with GUI managing, the event handler picks up the message from the queue, sees its a button push, fires up the "myaction" program, and moves on to handling the next event. Usually the "myaction" program will run as an idependent thread or even a separate process.
While the "event handler" pattern is more complex it is much more robust less likely to hang when an action fails. It also makes for a more responsive GUI.
I love how all these answers differ from each other.
I would conclude from this, is that from an a terminology point of view Events and Callbacks are interchangeable. What they mean in a specific programming language or framework and differ though, because any platform tends to pick their favourite terms.
Callback (from Wikipedia): "executable code that is passed as an argument to other code".
Event handler (again from Wikipedia): "asynchronous callback subroutine that handles inputs received in a program".
Which happens to be the way I've always understood it: an event handler is a very specific type of callback.