SlideShare a Scribd company logo
Stéphane Ducasse
Stéphane Ducasse
stephane.ducasse@inria.fr
http://stephane.ducasse.free.fr/
1
Exceptions...a simple
introduction
S.Ducasse 2
Standardized by ANSI in 1996
Exception is the root of the exception
hierarchy: 84 predefined exceptions. The two
most important classes are:
Error
Notification
Specialised into predefined exceptions ->
subclass them to create your own exceptions
Some methods of Exception:
defaultAction is executed when an exception occurs
description string describing the actual exception
Exceptions
S.Ducasse 3
|x y|
x := 7.
y := 0.
[x/y]
on: ZeroDivide
do: [:exception| Transcript show:
exception description, cr.
0....]
Catching an Exception
S.Ducasse 4
Signaling an Exception
Error signal
Warning signal: ‘description of the exception’
S.Ducasse 5
Exception
an Exception Handler is defined using on:do: and is
composed of
an exception class (ZeroDivide) and
a handler block [:theException| Transcript show: ‘ division
by zero’]
An Exception Handler completes by returning
the value of the handler block in place of the
value of the protected block (here [x/y]).
We can exit the current method by putting an
explicit return inside the handler block
S.Ducasse 6
The Main Exceptions of VW
Exception class Exceptional Event Default Action
Error Any program error Open a Notifier a Notifier
ArithmeticError
Any error evaluating an
arithmetic
Inherited from Error
MessageNotUnderstood
Any unusual event that
does not impair
continued execution of
the program
Inherited from Error
Notification
Notification Any
unusual event that does
not impair continued
execution of the
program Do nothing
continuing executing
Do nothing continuing
executing
An unusual event that Display Yes/No dialog
S.Ducasse 7
Exception Sets
[do some work]
on: ZeroDivide, Warning
do: [ :ex| what you want]
Or
|exceptionSets|
exceptionSets := ExceptionSet with: ZeroDivide
with: Warning.
[do some work]
on: exceptionSets
do: [ :ex| what you want]
Exception Sets
S.Ducasse 8
Each process has its own exception environment: an
ordered list of active handlers.
Process starts -> list empty
[aaaa] on: Error do: [bbb] -> Error,bbb added to the
beginning of the list
When an exception is signaled, the system sends a
message to the first handler of the exception handler.
If the handler cannot handle the exception, the next
one is asked
If no handler can handle the exception then the default
action is performed
Exception Environment
8
S.Ducasse 9
A handler block completes by executing the last
statement of the block. The value of the last statement
is then the value returned by the handler block.
Where this value should be returned depends:
Nonresumable (Error)
Sq: ([Error signal. ‘Value from protected
block’]
on: Error
do: [:ex|ex return: ‘Value from handler’])
> ‘Value from handler’
Resumable and Non-Resumable (i)
S.Ducasse 10
Resumable (Warning, Notification)
In this case Notification signal raises an exception,
then the context is restored and the value returned
normally
[Notification raiseSignal. ‘Value from protected block’]
on: Notification
do: [:ex|ex resume: ‘Value from handler’]
[Notification signal. 'Value from protected block']
on: Notification
do: [:ex|ex resume: 'Value from handler']
> ‘Value from protected Block’.
Resumable and Non-Resumable (ii)
S.Ducasse 11
Transcript show:
[Notification raiseSignal. 'Value from protected block']
on: Notification
do: [:ex| Transcript show: 'Entering handler '.
'Value from handler'. '5']
-> Entering handler 5
Resume:/Return:
S.Ducasse 12
Transcript show: [Notification raiseSignal. 'Value from
protected block']
on: Notification
do: [:ex| Transcript show: 'Entering handler '.
ex resume: 'Value from handler'. '5']
> Entering handler Value from protected block
Transcript show: [Notification raiseSignal. 'Value from
protected']
on: Notification
do: [:ex| Transcript show: 'Entering handler '.
ex return: 'Value from handler'. '5']
-> Entering handler Value from handler
Resume:/Return:
S.Ducasse 13
exit or exit: (VW specific) Resumes on a resumable
and returns on a nonresumable exception
resume or resume: Attempts to continue processing
the protected block, immeditely following the message
that triggered the exception.
return or return: ends processing the protected block
that triggered the exception
retry re-evaluates the protected block
retryUsing: evaluates a new block in place of the
protected block
Exiting Handlers Explicitly
S.Ducasse 14
resignalAs: resignal the exception as another on
pass exit the current handler and pass to the next
outer handler, control does not return to the passer
outer as with pass, except will regain control if the
outer handler resumes
exit:, resume: and return: return their argument as the
return value, instead of the value of the final statement
of the handler block
Exiting Handlers Explicitly (ii)
S.Ducasse 15
Look in Exception class examples categories
-2.0 to: 2.0 do: [ :i |
[ 10.0 / i. Transcript cr; show: i printString ]
on: Number divisionByZeroSignal do:
[:ex | Transcript cr; show: 'divideByZero abort'.
ex return ]
]
-2.0
-1.0
divideByZero abort
1.0
2.0
Examples
S.Ducasse 16
retry recreates the exception environment of active
handlers
[ x /y]
on: ZeroDivide
do: [:exception|
y := 0.00001.
exception retry]
Examples

More Related Content

What's hot

Os3 2
Os3 2Os3 2
Os3 2
issbp
 
Exp 8...
Exp 8...Exp 8...
Exp 8...
Harish Khodke
 
Func up your code
Func up your codeFunc up your code
Func up your code
Maciej Komorowski
 
Unit iii pds
Unit iii pdsUnit iii pds
Triggers
TriggersTriggers
Triggers
work
 
Arduino Code
Arduino CodeArduino Code
Arduino Code
shohanulislam5
 
Generator iterator methods
Generator iterator methodsGenerator iterator methods
Generator iterator methods
VikkyNangare1
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
MomenMostafa
 
Formalization Machines and Sastes
Formalization Machines and SastesFormalization Machines and Sastes
Formalization Machines and Sastes
Lahiru Danushka
 
Handling
HandlingHandling
Handling
Amit Vats
 

What's hot (10)

Os3 2
Os3 2Os3 2
Os3 2
 
Exp 8...
Exp 8...Exp 8...
Exp 8...
 
Func up your code
Func up your codeFunc up your code
Func up your code
 
Unit iii pds
Unit iii pdsUnit iii pds
Unit iii pds
 
Triggers
TriggersTriggers
Triggers
 
Arduino Code
Arduino CodeArduino Code
Arduino Code
 
Generator iterator methods
Generator iterator methodsGenerator iterator methods
Generator iterator methods
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
Formalization Machines and Sastes
Formalization Machines and SastesFormalization Machines and Sastes
Formalization Machines and Sastes
 
Handling
HandlingHandling
Handling
 

Viewers also liked

Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
The World of Smalltalk
 
Stoop 305-reflective programming5
Stoop 305-reflective programming5Stoop 305-reflective programming5
Stoop 305-reflective programming5
The World of Smalltalk
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
The World of Smalltalk
 
Stoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesignStoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesign
The World of Smalltalk
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
The World of Smalltalk
 
05 seaside
05 seaside05 seaside
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
The World of Smalltalk
 
Stoop 421-design heuristics
Stoop 421-design heuristicsStoop 421-design heuristics
Stoop 421-design heuristics
The World of Smalltalk
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
The World of Smalltalk
 
10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)
The World of Smalltalk
 
Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
The World of Smalltalk
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
The World of Smalltalk
 
10 reflection
10 reflection10 reflection
10 reflection
The World of Smalltalk
 
Stoop 303-advanced blocks
Stoop 303-advanced blocksStoop 303-advanced blocks
Stoop 303-advanced blocks
The World of Smalltalk
 
Stoop 431-visitor
Stoop 431-visitorStoop 431-visitor
Stoop 431-visitor
The World of Smalltalk
 
Stoop 437-proxy
Stoop 437-proxyStoop 437-proxy
Stoop 437-proxy
The World of Smalltalk
 
Double Dispatch
Double DispatchDouble Dispatch
Double Dispatch
The World of Smalltalk
 
10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)
The World of Smalltalk
 
7 - OOP - OO Concepts
7 - OOP - OO Concepts7 - OOP - OO Concepts
7 - OOP - OO Concepts
The World of Smalltalk
 
15 - Streams
15 - Streams15 - Streams

Viewers also liked (20)

Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop 305-reflective programming5
Stoop 305-reflective programming5Stoop 305-reflective programming5
Stoop 305-reflective programming5
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
Stoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesignStoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesign
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
05 seaside
05 seaside05 seaside
05 seaside
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
Stoop 421-design heuristics
Stoop 421-design heuristicsStoop 421-design heuristics
Stoop 421-design heuristics
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
 
10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)
 
Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
10 reflection
10 reflection10 reflection
10 reflection
 
Stoop 303-advanced blocks
Stoop 303-advanced blocksStoop 303-advanced blocks
Stoop 303-advanced blocks
 
Stoop 431-visitor
Stoop 431-visitorStoop 431-visitor
Stoop 431-visitor
 
Stoop 437-proxy
Stoop 437-proxyStoop 437-proxy
Stoop 437-proxy
 
Double Dispatch
Double DispatchDouble Dispatch
Double Dispatch
 
10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)
 
7 - OOP - OO Concepts
7 - OOP - OO Concepts7 - OOP - OO Concepts
7 - OOP - OO Concepts
 
15 - Streams
15 - Streams15 - Streams
15 - Streams
 

Similar to 14 - Exceptions

Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
Abid Kohistani
 
Exception handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread ProgrammingException handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread Programming
Prabu U
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
sanjay
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
Md. Tanvir Hossain
 
Exception handling
Exception handlingException handling
Exception handling
Iblesoft
 
Oop10 6
Oop10 6Oop10 6
Oop10 6
schwaa
 
MODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docxMODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docx
VeerannaKotagi1
 
Error and exception in python
Error and exception in pythonError and exception in python
Error and exception in python
junnubabu
 
Exception handling
Exception handlingException handling
Exception handling
Waqas Abbasi
 
6-Exception Handling and Templates.pptx
6-Exception Handling and Templates.pptx6-Exception Handling and Templates.pptx
6-Exception Handling and Templates.pptx
SatyamMishra237306
 
Lecture 09 Exception Handling(1 ) in c++.pptx
Lecture 09 Exception Handling(1 ) in c++.pptxLecture 09 Exception Handling(1 ) in c++.pptx
Lecture 09 Exception Handling(1 ) in c++.pptx
ZenLooper
 
Pl sql programme
Pl sql programmePl sql programme
Pl sql programme
Dhilip Prakash
 
Pl sql programme
Pl sql programmePl sql programme
Pl sql programme
Dhilip Prakash
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
Manav Prasad
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templates
farhan amjad
 
BLM101_2.pptx
BLM101_2.pptxBLM101_2.pptx
BLM101_2.pptx
ssuser4fbfbf
 
Object Oriented Programming using C++: Ch08 Operator Overloading.pptx
Object Oriented Programming using C++: Ch08 Operator Overloading.pptxObject Oriented Programming using C++: Ch08 Operator Overloading.pptx
Object Oriented Programming using C++: Ch08 Operator Overloading.pptx
RashidFaridChishti
 
PLSQL
PLSQLPLSQL
4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf
ShifatiRabbi
 
JavaHTP7e_1313_DDP.ppt
JavaHTP7e_1313_DDP.pptJavaHTP7e_1313_DDP.ppt
JavaHTP7e_1313_DDP.ppt
DrTouseefTahir
 

Similar to 14 - Exceptions (20)

Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
 
Exception handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread ProgrammingException handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread Programming
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Oop10 6
Oop10 6Oop10 6
Oop10 6
 
MODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docxMODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docx
 
Error and exception in python
Error and exception in pythonError and exception in python
Error and exception in python
 
Exception handling
Exception handlingException handling
Exception handling
 
6-Exception Handling and Templates.pptx
6-Exception Handling and Templates.pptx6-Exception Handling and Templates.pptx
6-Exception Handling and Templates.pptx
 
Lecture 09 Exception Handling(1 ) in c++.pptx
Lecture 09 Exception Handling(1 ) in c++.pptxLecture 09 Exception Handling(1 ) in c++.pptx
Lecture 09 Exception Handling(1 ) in c++.pptx
 
Pl sql programme
Pl sql programmePl sql programme
Pl sql programme
 
Pl sql programme
Pl sql programmePl sql programme
Pl sql programme
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templates
 
BLM101_2.pptx
BLM101_2.pptxBLM101_2.pptx
BLM101_2.pptx
 
Object Oriented Programming using C++: Ch08 Operator Overloading.pptx
Object Oriented Programming using C++: Ch08 Operator Overloading.pptxObject Oriented Programming using C++: Ch08 Operator Overloading.pptx
Object Oriented Programming using C++: Ch08 Operator Overloading.pptx
 
PLSQL
PLSQLPLSQL
PLSQL
 
4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf
 
JavaHTP7e_1313_DDP.ppt
JavaHTP7e_1313_DDP.pptJavaHTP7e_1313_DDP.ppt
JavaHTP7e_1313_DDP.ppt
 

More from The World of Smalltalk

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
The World of Smalltalk
 
99 questions
99 questions99 questions
13 traits
13 traits13 traits
11 bytecode
11 bytecode11 bytecode
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
The World of Smalltalk
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
The World of Smalltalk
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
The World of Smalltalk
 
06 debugging
06 debugging06 debugging
04 idioms
04 idioms04 idioms
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
The World of Smalltalk
 
02 basics
02 basics02 basics
01 intro
01 intro01 intro
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
The World of Smalltalk
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
The World of Smalltalk
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
The World of Smalltalk
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
The World of Smalltalk
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
The World of Smalltalk
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
The World of Smalltalk
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
The World of Smalltalk
 

More from The World of Smalltalk (20)

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
 
99 questions
99 questions99 questions
99 questions
 
13 traits
13 traits13 traits
13 traits
 
11 bytecode
11 bytecode11 bytecode
11 bytecode
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
06 debugging
06 debugging06 debugging
06 debugging
 
04 idioms
04 idioms04 idioms
04 idioms
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
02 basics
02 basics02 basics
02 basics
 
01 intro
01 intro01 intro
01 intro
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
 

Recently uploaded

writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Diana Rendina
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 

Recently uploaded (20)

writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 

14 - Exceptions

  • 2. S.Ducasse 2 Standardized by ANSI in 1996 Exception is the root of the exception hierarchy: 84 predefined exceptions. The two most important classes are: Error Notification Specialised into predefined exceptions -> subclass them to create your own exceptions Some methods of Exception: defaultAction is executed when an exception occurs description string describing the actual exception Exceptions
  • 3. S.Ducasse 3 |x y| x := 7. y := 0. [x/y] on: ZeroDivide do: [:exception| Transcript show: exception description, cr. 0....] Catching an Exception
  • 4. S.Ducasse 4 Signaling an Exception Error signal Warning signal: ‘description of the exception’
  • 5. S.Ducasse 5 Exception an Exception Handler is defined using on:do: and is composed of an exception class (ZeroDivide) and a handler block [:theException| Transcript show: ‘ division by zero’] An Exception Handler completes by returning the value of the handler block in place of the value of the protected block (here [x/y]). We can exit the current method by putting an explicit return inside the handler block
  • 6. S.Ducasse 6 The Main Exceptions of VW Exception class Exceptional Event Default Action Error Any program error Open a Notifier a Notifier ArithmeticError Any error evaluating an arithmetic Inherited from Error MessageNotUnderstood Any unusual event that does not impair continued execution of the program Inherited from Error Notification Notification Any unusual event that does not impair continued execution of the program Do nothing continuing executing Do nothing continuing executing An unusual event that Display Yes/No dialog
  • 7. S.Ducasse 7 Exception Sets [do some work] on: ZeroDivide, Warning do: [ :ex| what you want] Or |exceptionSets| exceptionSets := ExceptionSet with: ZeroDivide with: Warning. [do some work] on: exceptionSets do: [ :ex| what you want] Exception Sets
  • 8. S.Ducasse 8 Each process has its own exception environment: an ordered list of active handlers. Process starts -> list empty [aaaa] on: Error do: [bbb] -> Error,bbb added to the beginning of the list When an exception is signaled, the system sends a message to the first handler of the exception handler. If the handler cannot handle the exception, the next one is asked If no handler can handle the exception then the default action is performed Exception Environment 8
  • 9. S.Ducasse 9 A handler block completes by executing the last statement of the block. The value of the last statement is then the value returned by the handler block. Where this value should be returned depends: Nonresumable (Error) Sq: ([Error signal. ‘Value from protected block’] on: Error do: [:ex|ex return: ‘Value from handler’]) > ‘Value from handler’ Resumable and Non-Resumable (i)
  • 10. S.Ducasse 10 Resumable (Warning, Notification) In this case Notification signal raises an exception, then the context is restored and the value returned normally [Notification raiseSignal. ‘Value from protected block’] on: Notification do: [:ex|ex resume: ‘Value from handler’] [Notification signal. 'Value from protected block'] on: Notification do: [:ex|ex resume: 'Value from handler'] > ‘Value from protected Block’. Resumable and Non-Resumable (ii)
  • 11. S.Ducasse 11 Transcript show: [Notification raiseSignal. 'Value from protected block'] on: Notification do: [:ex| Transcript show: 'Entering handler '. 'Value from handler'. '5'] -> Entering handler 5 Resume:/Return:
  • 12. S.Ducasse 12 Transcript show: [Notification raiseSignal. 'Value from protected block'] on: Notification do: [:ex| Transcript show: 'Entering handler '. ex resume: 'Value from handler'. '5'] > Entering handler Value from protected block Transcript show: [Notification raiseSignal. 'Value from protected'] on: Notification do: [:ex| Transcript show: 'Entering handler '. ex return: 'Value from handler'. '5'] -> Entering handler Value from handler Resume:/Return:
  • 13. S.Ducasse 13 exit or exit: (VW specific) Resumes on a resumable and returns on a nonresumable exception resume or resume: Attempts to continue processing the protected block, immeditely following the message that triggered the exception. return or return: ends processing the protected block that triggered the exception retry re-evaluates the protected block retryUsing: evaluates a new block in place of the protected block Exiting Handlers Explicitly
  • 14. S.Ducasse 14 resignalAs: resignal the exception as another on pass exit the current handler and pass to the next outer handler, control does not return to the passer outer as with pass, except will regain control if the outer handler resumes exit:, resume: and return: return their argument as the return value, instead of the value of the final statement of the handler block Exiting Handlers Explicitly (ii)
  • 15. S.Ducasse 15 Look in Exception class examples categories -2.0 to: 2.0 do: [ :i | [ 10.0 / i. Transcript cr; show: i printString ] on: Number divisionByZeroSignal do: [:ex | Transcript cr; show: 'divideByZero abort'. ex return ] ] -2.0 -1.0 divideByZero abort 1.0 2.0 Examples
  • 16. S.Ducasse 16 retry recreates the exception environment of active handlers [ x /y] on: ZeroDivide do: [:exception| y := 0.00001. exception retry] Examples