Skip to main content
Engineering LibreTexts

12.13: Example — Halt Implementation

  • Page ID
    45973
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    As discussed in the Debugger chapter of Pharo By Example, the usual way of setting a breakpoint within a Smalltalk method is to insert the message-send self halt into the code. The method halt, implemented in Object, uses exceptions to open a debugger at the location of the breakpoint; it is defined as follows:

    Object»halt
        "This is the typical message to use for inserting breakpoints during
        debugging. It behaves like halt:, but does not call on halt: in order to
        avoid putting this message on the stack. Halt is especially useful when
        the breakpoint message is an arbitrary one."
        Halt signal
    

    Halt is a direct subclass of Exception. A Halt exception is resumable, which means that it is possible to continue execution after a Halt is signaled.

    Halt overrides the defaultAction method, which specifies the action to perform if the exception is not caught (i.e., there is no exception handler for Halt anywhere on the execution stack):

    Halt»defaultAction
        "No one has handled this error, but now give them a chance to decide
        how to debug it. If no one handles this then open debugger
        (see UnhandedError-defaultAction)"
        UnhandledError signalForException: self 
    

    This code signals a new exception, UnhandledError, that conveys the idea that no handler is present. The defaultAction of UnhandledError is to open a debugger:

    UnhandledError»defaultAction
        "The current computation is terminated. The cause of the error should be logged or
            reported to the user. If the program is operating in an interactive debugging
            environment the computation should be suspended and the debugger activated."
        ^ UIManager default unhandledErrorDefaultAction: self exception 
    
    MorphicUIManager»unhandledErrorDefaultAction: anException
        ^ Smalltalk tools debugError: anException.
    

    A few messages later, the debugger opens:

    Process»debug: context title: title full: bool
        ^ Smalltalk tools debugger
            openOn: self
            context: context
            label: title
            contents: nil
            fullView: bool.
    

    This page titled 12.13: Example — Halt Implementation is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Alexandre Bergel, Damien Cassou, Stéphane Ducasse, Jannik Laval (Square Bracket Associates) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.