Design by Contract and Error Handling

4 downloads 10513 Views 157KB Size Report
Design by Contract. (DbC). Systematic. Approaches for Error. Handling. Internal and external errors. Defensive. Programming. Typed Exceptions and. Try/Catch.
Design by Contract and Error Handling

Design by Contract and Error Handling

Context Design by Contract (DbC) Systematic Approaches for Error Handling Internal and external errors

Miguel Oliveira e Silva ([email protected]) and Pedro G. Francisco ([email protected]) DETI / IEETA, Universidade de Aveiro

SLATE’14, Bragança, 19th and 20th June, 2014

Defensive Programming Typed Exceptions and Try/Catch DbC Exception Mechanism Fault Tolerance in DbC

Conclusions

1

Context

Design by Contract and Error Handling

Context Design by Contract (DbC)

The Problem

Easy the construction of correct and robust programs. • A program always contains a precise meaning . . . but

frequently is not what the programmer intended. • Modular approaches to programming aid in reducing this

Systematic Approaches for Error Handling Internal and external errors

Defensive Programming Typed Exceptions and Try/Catch DbC Exception Mechanism Fault Tolerance in DbC

Conclusions

gap . . . but a proper confrontation with programmer’s semantic goals is required. • Commenting programs might be a first approach towards

this goal . . . but not only programmers neglect them, but also frequently is not the program’s meaning. • A better approach is to explicitly attach meaning to

programs is required! 2

Design by Contract and Error Handling

Design by Contract (DbC)

Context Design by Contract (DbC)

DbC

Programming methodology in which the meaning of program entities is made explicit by the use assertions.

Internal and external errors

Defensive Programming Typed Exceptions and Try/Catch DbC Exception Mechanism

Native Java s t a t i c double s q r t ( double x ) { a s s e r t x >= 0 ; double r e s u l t ; ··· a s s e r t Math . abs ( r e s u l t ∗ r e s u l t − x ) = 0 ; { ··· } ensures Math . abs ( r e s u l t ∗ r e s u l t − x ) = 1 && month = 28 && r e s u l t