Abstract
Exceptions are an indispensable part of modern programming languages. They are, however, handled poorly, especially by higherorder languages such as Standard ML and Haskell: in both languages a well-typed program can unexpectedly fail due to an uncaught exception. In this paper, we propose a technique for type-safe exception handling. Our approach relies on representing exceptions as sums and assigning exception handlers polymorphic, extensible row types. Based on this representation, we describe an implicitly typed external language EL where well-typed programs do not raise any unhandled exceptions. EL relies on sums, extensible records, and polymorphism to represent exceptionhandling, and its type system is no more complicated than that for existing languages with polymorphic extensible records.
EL is translated into an internal language IL that is a variant of System F extended with extensible records. The translation performs a CPS transformation to represent exception handlers as continuations. It also relies on duality to transform sums into records. (The details for this translation are given in an accompanying technical report.)
We describe the implementation of a compiler for a concrete language based on EL. The compiler performs full type inference and translates EL-style source code to machine code. Type inference relieves the programmer from having to provide explicit exception annotations. We believe that this is the first practical proposal for integrating exceptions into the type system of a higher-order language.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Appel, A.W., MacQueen, D.B.: Standard ML of New Jersey. In: Third International Symp. on Prog. Lang. Implementation and Logic Programming, pp. 1–13 ( August 1991)
Benton, N., Buchlovsky, P.: Semantics of an effect analysis for exceptions. In: TLDI 2007, pp. 15–26. ACM, New York (2007)
Benton, N., Kennedy, A.: Exceptional syntax. J. Funct. Program. 11(4), 395–410 (2001)
Blume, M., Acar, U.A., Chae, W.: Extensible programming with first-class cases. In: ICFP 2006: Proceedings of the eleventh ACM SIGPLAN international conference on Functional programming, pp. 239–250. ACM, New York (2006)
Blume, M., Acar, U.A., Chae, W.: Exception handlers as extensible cases. U.Chicago, Computer Sci. Tech. Report TR-2008-03 (February 2008)
Cardelli, L., Donahue, J., Glassman, L., Jordan, M., Kalsow, B., Nelson, G.: Modula-3 report. Technical Report Research Report 31, DEC SRC (1988)
Fähndrich, M., Foster, J., Cu, J., Aiken, A.: Tracking down exceptions in Standard ML programs. Technical Report CSD-98-996, UC Berkeley (February 1998)
Felleisen, M., Hieb, R.: A revised report on the syntactic theories of sequential control and state. Theoretical Computer Science 103(2), 235–271 (1992)
Gansner, E.R., Reppy, J.H.: The Standard ML Basis Library. Cambridge University Press, Cambridge (2002)
Gosling, J., Joy, B., Steele, G., Bracha, G.: Java Language Specification, 2nd edn. The Java Series. Addison Wesley, Reading (2000)
Guzmán, J., Suárez, A.: An extended type system for exceptions. In: ACM SIGPLAN Workshop on ML and its Applications (1994)
Henglein, F.: Type inference with polymorphic recursion. ACM Trans. Program. Lang. Syst. 15(2), 253–289 (1993)
Leroy, X.: The Objective Caml System (1996), http://caml.inria.fr/ocaml
Leroy, X., Pessaux, F.: Type-based analysis of uncaught exceptions. ACM Trans. Program. Lang. Syst. 22(2), 340–377 (2000)
Lions, J.L.: Ariane 5, flight 501 failure, report by the inquiry board (1996), http://sunnyday.mit.edu/accidents/Ariane5accidentreport.html
Liskov, B., Atkinson, R., Bloom, T., Moss, E., Schaffert, J.C., Scheifler, R., Snyder, A.: CLU Reference Manual. Springer, New York (1981)
Ohori, A.: A polymorphic record calculus and its compilation. ACM Trans. Program. Lang. Syst. 17(6), 844–895 (1995)
Yi, K.: An abstract interpretation for estimating uncaught exceptions in Standard ML programs. Sci. Comput. Program. 31(1) (1998)
Yi, K., Ryu, S.: Towards a cost-effective estimation of uncaught exceptions in sml programs. In: Van Hentenryck, P. (ed.) SAS 1997. LNCS, vol. 1302, pp. 98–113. Springer, Heidelberg (1997)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2008 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Blume, M., Acar, U.A., Chae, W. (2008). Exception Handlers as Extensible Cases. In: Ramalingam, G. (eds) Programming Languages and Systems. APLAS 2008. Lecture Notes in Computer Science, vol 5356. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-89330-1_20
Download citation
DOI: https://doi.org/10.1007/978-3-540-89330-1_20
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-89329-5
Online ISBN: 978-3-540-89330-1
eBook Packages: Computer ScienceComputer Science (R0)