How to catch a Stop the Build event in code?

In my plugin that I’m developing I run an external process. In case the user decides to stop the build another external process needs to be run in order to stop the execution of the former.

How can I catch an event of a stop build? I couldn’t find any exceptions thrown when clicking the “Stop the Build” button.