
Exception Handling in an Event-Driven System Jan Ploski Wilhelm Hasselbring Business Information Management Software Engineering Group OFFIS Institute for Information Technology University of Oldenburg 26121 Oldenburg, Germany 26111 Oldenburg, Germany jan.ploski@offis.de [email protected] Abstract to a method’s invoker, does not apply to event-driven sys- tems. The data collected in the case study serves to support Exception handling mechanisms were invented in 1970s our analysis. When considered separately, our results speak to support structured programming methods for hierarchi- against an event-driven architecture. If such an architecture cally organised software systems. The need to increase is preferred for other reasons, developers must take into ac- reusability and flexibility led to the development of new pro- count that the language mechanisms will likely be insuffi- gramming paradigms that do not emphasise hierarchical cient for exception handling and devote special attention to design. Event-driven systems—in which objects communi- language-neutral alternatives. cate using notifications about changed states—are a prime In Section 2 we discuss how early work on exception example. Unfortunately, this style of communication makes handling relates to structured programming and why current exception handling more difficult than in hierarchical sys- exception handling mechanisms are appropriate for hierar- tems. chically structured software. Section 3 presents a rationale We contribute an analysis of the factors which influence for event-driven systems, in which objects react to new in- exception handling in event-driven systems. The main focus formation rather than to commands issued by other objects. of our discussion lies on the challenge of appropriate ex- We provide several examples showing that this style of com- ception propagation. We provide results from an empirical munication is independent from the issues of concurrency. case study performed on the source code of the Eclipse IDE In Section 4 we focus on the exception propagation from that support our analysis. event handlers. Section 5 contains results of our empirical study. We present our results in Section 6 and conclude with a discussion of related work. 1. Introduction 2. The origins of exception handling When exception handling mechanisms were introduced into programming languages in 1970s software systems Exception handling was first proposed as a syntactic ex- were often designed and implemented from scratch accord- tension to languages which supported structured program- ing to the principles of structured programming. Today, ming. Unsurprisingly, exception handling mechanisms are system builders are much more concerned with integrating strongly related to structured programming. the available pre-built components and installed products. We wish to stress that some design assumptions in excep- Event-driven systems are a popular method of software in- tion handling mechanisms do not fit the features of modern tegration. event-driven systems. We first explain why they are correct Unlike software architectures, exception handling mech- with respect to the original target systems. anisms offered by mainstream programming languages have not changed much since 1970s. Additionally, there 2.1. Structured programming are few rules for discerning between the “good” and “bad” practices of exception handling with respect to software ar- Structured programming is concerned with decomposing chitecture and empirical evaluation is rarely attempted by software systems into modules and defining desirable rela- researchers. tionships among these modules. In this paper we observe that the traditional approach to A module consists of (optional) storage space along with exception handling, which relies on exception propagation operations which present an abstraction of the managed Second International Conference on Availability, Reliability and Security (ARES'07) 0-7695-2775-2/07 $20.00 © 2007 state to its clients. In that respect, a traditional structured rithms hard-wired into modules represent strong assump- programming module resembles an object. Only a single in- tions about their clients. To improve reuse, structured pro- stance of a module exists in the system at run-time. Hence, gramming avoids such assumptions. Therefore, the excep- modules can be thought of as singleton classes [7]. The tion handling technique proposed by Parnas and Wurges¨ services provided by a module are either computations or supports deferral of exception handling decisions, but en- input/output operations on hardware. courages early and preferably automated detection of errors. Structured programming recommends dividing the The choice of where to delegate the exception handling knowledge captured in a software system into modules to responsibility is obvious in structured programming: as a increase the locality of anticipated implementation changes. consequence of hierarchical design, the higher-level opera- Local changes are easier to incorporate and less error-prone. tions maintain more information about the execution con- Operations provided by modules should be organised in a text. This fact makes them likely candidates for performing strict hierarchy defined by their “use” relationships, with recovery or diagnostic reporting. For example, a high level higher-level operations invoking lower-level ones [17]. program may “know” whether it is run in interactive mode Higher-level operations also need to be protected from with a human user capable of reacting to console error mes- “knowing” the secrets about data structures and algorithms sages or in batch mode where logging or automatic retry encapsulated by modules enclosing the lower-level opera- might be preferable. In short, hierarchical systems support tions. Again, the reason is to constrain the effects of a exception handling by escalation of problem information in system’s modification (information hiding, cf. [16]). More- the hierarchy. over, the lower-level operations should be kept unaware of their clients to foster reuse. 2.3. Exception handling vs. information hiding Overall, structured programming improves software maintenance by making changes easier to manage and de- Parnas and Wurges¨ [18] explain the implicit limitations veloper responsibilities easier to assign. of exception handling concepts based on their ties to struc- tured programming. They recognise that the possibility of 2.2. Structured exception handling exceptions clashes with the goals of information hiding: “Unless we abandon the idea of abstraction completely, no Structured programming did not originally include lan- design always presents all of the information usable for re- guage support for run-time error handling. Language de- covery”. Propagating an exception upwards the call chain in signers soon recognised this omission and invented the a lower level operation’s execution may leave the enclosing mechanisms that shape our present way of thinking about module in an unspecified state. However, the client can only exception handling. For example, Goodenough’s work [8] rely on specified states of the used module. As a remedy, laid foundations for control flow constructs present in mod- Parnas and Wurges¨ recommend making the module’s inter- ern languages. face more granular. It should always be detailed enough to A less referenced, yet equally insightful publication from support reasoning about potential run-time problems. Con- the same period is by Parnas and Wurges¨ [18]. Rather than sequently, some states that could remain hidden if no excep- focus on syntax, the authors point out the potential goal con- tions were possible may need to be exposed for the sake of flicts between information hiding and exception handling. enabling recovery. A similar approach can be found again These conflicts have become increasingly relevant with the in Cristian’s later formalisation of exception handling in se- adoption of methods such as event-driven programming. quential programs [5]. However, Cristian treats exceptions Parnas and Wurges¨ observe that even verifiably correct as extensions to specifications of individual operations. He programs have to account for “undesired events” (which we does not reflect on module-scope design issues. The dif- now call “exceptions”). Examples are bugs, hardware fail- ference is subtle, yet important. We shall return to it when ures, but also inconsistent data inputs, beyond the system’s discussing the results of our case study (Section 6). control. Some exceptions can be anticipated during design. Information hiding and recovery requirements conflict However, many are only revealed during the initial period even more visibly in object-oriented systems [14]. These of software use. Therefore, it is practical to design software systems are more dynamic and apply abstraction on a flexibly enough to introduce exception handlers later, after greater scale than traditional structured programming. In we have learned about the most common or critical faults. structured systems, the correspondence between the imple- Importantly, while we need to design programs to en- mentation of a module and its specification can be checked able exception handling, we do not need (and perhaps even statically at compile time. Object-orientation encourages cannot) implement the recovery algorithms early. First, an- compile-time implementation independence through late ticipating faults is difficult. Second, overeager error han- binding. An object’s
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages8 Page
-
File Size-