Institute for Software Research International
School of Computer Science, Carnegie Mellon University
Neel Krishnaswami, Jonathan Aldrich
This report was originally published on the web in January 2004.
We propose statically-scoped exceptions as an alternative mechanism for error-handling. In our system, a thrown exception is caught by the nearest lexically-enclosing exception handler, rather than the nearest handler on the call stack. Using static scoping allows us to achieve better modularization, as with AspectJ, and also precudes the problem of exception capture. We provide a static type system that tracks exceptions precisely and ensures that statically-scoped exceptions cannot be misused to cause continuation-like behavior. We hope that our system will serve as a foundation for error handling mechanisms that combine good modularization with strong static reasoning about errors.