I am trying to learn some programming related terms, and I often come over the word "handler". Can anyone please explain what it means and when to use it?
-
1In Computer Science, this term is typically used in operating systems and other system software development. When used in this context, the term `handler` could be making reference to a software routine/procedure or event that performs a particular task. In some cases, the term `handler` could also be making reference to a routine that `"handles"` an exception of some kind, such as an error, but it can refer to mainstream processes as well. [Check out this wiki reference](https://en.wikipedia.org/wiki/Handler?#Computing) – 0xe1λ7r Feb 20 '22 at 22:13
3 Answers
A handler is a routine/function/method which is specialized in a certain type of data or focused on certain special tasks.
Examples:
Event handler - Receives and digests events and signals from the surrounding system (e.g. OS or GUI).
Memory handler - Performs certain special tasks on memory.
File input handler - A function receiving file input and performing special tasks on the data, all depending on context of course.
Code that's associated with and triggered by the occurrence of a specific event, like an incoming message, a thrown exception, a signal sent to a process, a network I/O request completing, or a mouse click on a user interface element. It's a very generic term.

- 13,375
- 13
- 47
- 46
-
3That's an event handler. The OP was asking about the less specific term "handler". – Jimbo Jun 19 '18 at 14:47
I think it's a very general term, without a 'hard' definition. The meaning is highly contextual, varies depending on the general code design.
For me, it usually means some code that is called from an inner core and is supposed to do some things and return. That 'inner' part can have several 'handlers' available, and chooses which one to call.
In some cases, you define some API to make those handlers mostly interchangeable, so the caller can pick one from a table and use the same code to call any of them. OOP helps a lot here.

- 60,510
- 8
- 78
- 126