The HHVM project suggests an interesting Lazy backtrace generation
mechanism based on stack unwinding.


   1.

   An exception is generated.
   2.

   The stack enters an unwinding mode. In this mode, PHP gradually collects
   information into the backtrace.
   3.

   Each frame exit contributes a part of the backtrace.
   4.

   Once the exception is caught, the unwinding process stops.
   5.

    Now a decision can be made: either generate the full backtrace or
   suppress the exception.


Advantages:

   1.

   Allows deferring backtrace generation until the exception is caught.
   2.

   Allows suppressing exceptions without a backtrace, making their creation
   cost cheap.
   3.

   Allows preserving exceptions with a backtrace only when necessary.

Disadvantages: requires added complexity.

Reply via email to