SlideShare a Scribd company logo
1 of 20
Download to read offline
Exceptions
           Asif Tasleem

       asiftasleem@gmail.com
      asiftasleem.blogspot.com
http://sa.linkedin.com/in/asiftasleem
What is an Exception?
• An exception is an event, which occurs during the
  execution of a program, that disrupts the normal
  flow of the program's instructions.
Throwable Family
Exceptions Types
• Checked Exceptions
  – These are exceptional conditions that a well-written application should
    anticipate and recover from. Checked exceptions  are subject to the
    Catch or Specify Requirement.

• Error
  – These are exceptional conditions that are external to the application,
    and that the application usually cannot anticipate or recover from.
    Errors are not subject to the Catch or Specify Requirement. 

• Runtime Exceptions
  – These are exceptional conditions that are internal to the application, and
    that the application usually cannot anticipate or recover from. These
    usually indicate programming bugs, such as logic errors or improper use
    of an API. Runtime exceptions are not subject to the Catch or Specify
    Requirement.
Exceptions Types
Why Exceptions
1: Separating Error-Handling
     Code from "Regular" Code
• Consider the pseudocode method here that reads an entire file
  into memory.
readFile {
     open the file;
     determine its size;
     allocate that much memory;
     read the file into memory;
     close the file;
}
1: Separating Error-Handling Code from
               "Regular" Code (Cont.)

At first glance, this function seems simple
enough, but it ignores all the following
potential errors.
   –   What happens if the file can't be opened?
   –   What happens if the length of the file can't be
       determined?
   –   What happens if enough memory can't be
       allocated?
   –   What happens if the read fails?
   –   What happens if the file can't be closed?
1: Separating Error-Handling Code from
        "Regular" Code (Cont.)
1: Separating Error-Handling Code from
        "Regular" Code (Cont.)
2: Propagating Errors Up the
         Call Stack
2: Propagating Errors Up the
      Call Stack (Cont.)
2: Propagating Errors Up the
      Call Stack (Cont.)
 3: Grouping and Differentiating
          Error Types
• As all exceptions thrown within a program are objects, the grouping
  or categorizing of exceptions is a natural outcome of the class
  hierarchy. 
  – A handler can handle only one type of exception.
  – catch (FileNotFoundException e) {
        ...

  – }
  – A handler can handle a group of exceptions.
  – catch (IOException e) {
        ...

  – }
  – We could even set up an exception handler that handles any Exception catch
    (Exception e) {
        ...

  – }
Designing with Exceptions
Exceptions indicate a
        broken contract
• Design by Contract
  – A software design approach that says that a method represents a contract between the client
    (the caller of the method) and the class that declares the method. The contract includes
    preconditions that the client must fulfill and post conditions that the method itself must fulfill.

• Precondition
  – One example of a method with a precondition is the charAt(int index) method of
    class String. This method requires that the index parameter passed by the client be
    between 0 and one less than the value returned by invoking length() on the String object.
    In other words, if the length of a String is 5, the index parameter must be between 0 and
    4, inclusive.
• Postcondition
  – The postcondition of String's charAt(int index) method is that its return value will be
    the character at position index and the string itself will remain unchanged.
Unchecked Exceptions
    The Controversy
• Don’t create a subclass
  of RuntimeException simply because you don't
  want to be bothered with specifying the
  exceptions your methods can throw.
What to throw?
• Exception vs Error
  – Leave the errors to the big guys.

• Checked vs Unchecked exceptions
  – If you are throwing an exception for an abnormal condition
    that you feel client programmers should consciously decide
    how to handle, throw a checked exception.

• Define a specific exception class
  – Don't just throw Exception, for example, with a string
    message indicating the kind of abnormal condition that
    caused the exception. 
What to throw? (Cont.)
• If your method encounters an abnormal condition that it can't handle, it
  should throw an exception.
• Avoid using exceptions to indicate conditions that can reasonably be
  expected as part of the normal functioning of the method.
• If your method discovers that the client has breached its contractual
  obligations (for example, by passing in bad input data), throw an
  unchecked exception.
• If your method is unable to fulfill its contract, throw either a checked or
  unchecked exception.
• If you are throwing an exception for an abnormal condition that you feel
  client programmers should consciously decide how to handle, throw a
  checked exception.
• Define or choose an already existing exception class for each kind of
  abnormal condition that may cause your method to throw an exception.
Thank You

More Related Content

What's hot

Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCode Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCefalo
 
Quality Software With Unit Test
Quality Software With Unit TestQuality Software With Unit Test
Quality Software With Unit Testalice yang
 
Using pmd to ensure apex coding best practices
Using pmd to ensure apex coding best practicesUsing pmd to ensure apex coding best practices
Using pmd to ensure apex coding best practicesAhmed Keshk
 
Programming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStringsProgramming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStringsAlan Richardson
 
Training material exceptions v1
Training material   exceptions v1Training material   exceptions v1
Training material exceptions v1Shinu Suresh
 
5 black box and grey box testing
5   black box and grey box testing5   black box and grey box testing
5 black box and grey box testingYisal Khan
 
Defencive programming
Defencive programmingDefencive programming
Defencive programmingAsha Sari
 
Defensive programming
Defensive programmingDefensive programming
Defensive programmingEben Cheung
 
Week7 exception handling
Week7 exception handlingWeek7 exception handling
Week7 exception handlingAlpesh Oza
 
Error handling and debugging
Error handling and debuggingError handling and debugging
Error handling and debuggingsalissal
 
Code sense
Code senseCode sense
Code sensenasirj
 
How To Use Ignore Annotation In JUnit
How To Use Ignore Annotation In JUnitHow To Use Ignore Annotation In JUnit
How To Use Ignore Annotation In JUnitBugRaptors
 
Design Test Case Technique (Equivalence partitioning And Boundary value analy...
Design Test Case Technique (Equivalence partitioning And Boundary value analy...Design Test Case Technique (Equivalence partitioning And Boundary value analy...
Design Test Case Technique (Equivalence partitioning And Boundary value analy...Ryan Tran
 
White box testing
White box testing White box testing
White box testing Mani Kanth
 
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean DevelopmentRakuten Group, Inc.
 
Implementing Blackbox Testing
Implementing Blackbox TestingImplementing Blackbox Testing
Implementing Blackbox TestingEdureka!
 
Structural testing
Structural testingStructural testing
Structural testingSlideshare
 

What's hot (20)

Debugging
DebuggingDebugging
Debugging
 
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCode Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
 
Quality Software With Unit Test
Quality Software With Unit TestQuality Software With Unit Test
Quality Software With Unit Test
 
Using pmd to ensure apex coding best practices
Using pmd to ensure apex coding best practicesUsing pmd to ensure apex coding best practices
Using pmd to ensure apex coding best practices
 
Programming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStringsProgramming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStrings
 
Training material exceptions v1
Training material   exceptions v1Training material   exceptions v1
Training material exceptions v1
 
5 black box and grey box testing
5   black box and grey box testing5   black box and grey box testing
5 black box and grey box testing
 
Defencive programming
Defencive programmingDefencive programming
Defencive programming
 
Defensive programming
Defensive programmingDefensive programming
Defensive programming
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 
Week7 exception handling
Week7 exception handlingWeek7 exception handling
Week7 exception handling
 
Error handling and debugging
Error handling and debuggingError handling and debugging
Error handling and debugging
 
Code sense
Code senseCode sense
Code sense
 
How To Use Ignore Annotation In JUnit
How To Use Ignore Annotation In JUnitHow To Use Ignore Annotation In JUnit
How To Use Ignore Annotation In JUnit
 
Design Test Case Technique (Equivalence partitioning And Boundary value analy...
Design Test Case Technique (Equivalence partitioning And Boundary value analy...Design Test Case Technique (Equivalence partitioning And Boundary value analy...
Design Test Case Technique (Equivalence partitioning And Boundary value analy...
 
White box testing
White box testing White box testing
White box testing
 
Debbuging
DebbugingDebbuging
Debbuging
 
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
 
Implementing Blackbox Testing
Implementing Blackbox TestingImplementing Blackbox Testing
Implementing Blackbox Testing
 
Structural testing
Structural testingStructural testing
Structural testing
 

Viewers also liked

Social media training CultuurSchakel Handout - 30 nov
Social media training CultuurSchakel Handout - 30 novSocial media training CultuurSchakel Handout - 30 nov
Social media training CultuurSchakel Handout - 30 novKim Swagemakers | KIMPACT
 
Dấu hiệu nhận biết sớm triệu chứng đột quỵ để phòng tránh
Dấu hiệu nhận biết sớm triệu chứng đột quỵ để phòng tránhDấu hiệu nhận biết sớm triệu chứng đột quỵ để phòng tránh
Dấu hiệu nhận biết sớm triệu chứng đột quỵ để phòng tránhcletus204
 
Bx i agzuln0ggbawa1iusvennm6cl2yz4sxnfyyxl1kg2mcfii36tmvidgsnbknqu
Bx i agzuln0ggbawa1iusvennm6cl2yz4sxnfyyxl1kg2mcfii36tmvidgsnbknquBx i agzuln0ggbawa1iusvennm6cl2yz4sxnfyyxl1kg2mcfii36tmvidgsnbknqu
Bx i agzuln0ggbawa1iusvennm6cl2yz4sxnfyyxl1kg2mcfii36tmvidgsnbknquSupipat Mokmamern
 
Nguy cơ mất trí nhớ, Alzheimer do đãng trí, hay quên
Nguy cơ mất trí nhớ, Alzheimer do đãng trí, hay quênNguy cơ mất trí nhớ, Alzheimer do đãng trí, hay quên
Nguy cơ mất trí nhớ, Alzheimer do đãng trí, hay quênqiana831
 
Sistemas Operativos (Informaciones)
Sistemas Operativos (Informaciones)Sistemas Operativos (Informaciones)
Sistemas Operativos (Informaciones)Diomelvi Mendoza
 

Viewers also liked (12)

Social media training CultuurSchakel Handout - 30 nov
Social media training CultuurSchakel Handout - 30 novSocial media training CultuurSchakel Handout - 30 nov
Social media training CultuurSchakel Handout - 30 nov
 
Bill gates speak
 Bill gates speak Bill gates speak
Bill gates speak
 
Niños heroes prezi
Niños heroes preziNiños heroes prezi
Niños heroes prezi
 
Dấu hiệu nhận biết sớm triệu chứng đột quỵ để phòng tránh
Dấu hiệu nhận biết sớm triệu chứng đột quỵ để phòng tránhDấu hiệu nhận biết sớm triệu chứng đột quỵ để phòng tránh
Dấu hiệu nhận biết sớm triệu chứng đột quỵ để phòng tránh
 
Misterios de los astonautas
Misterios de los astonautasMisterios de los astonautas
Misterios de los astonautas
 
Aula virtual
Aula virtualAula virtual
Aula virtual
 
Compro VIP 2015
Compro VIP 2015Compro VIP 2015
Compro VIP 2015
 
Examen6tolorena
Examen6tolorenaExamen6tolorena
Examen6tolorena
 
Bx i agzuln0ggbawa1iusvennm6cl2yz4sxnfyyxl1kg2mcfii36tmvidgsnbknqu
Bx i agzuln0ggbawa1iusvennm6cl2yz4sxnfyyxl1kg2mcfii36tmvidgsnbknquBx i agzuln0ggbawa1iusvennm6cl2yz4sxnfyyxl1kg2mcfii36tmvidgsnbknqu
Bx i agzuln0ggbawa1iusvennm6cl2yz4sxnfyyxl1kg2mcfii36tmvidgsnbknqu
 
Nguy cơ mất trí nhớ, Alzheimer do đãng trí, hay quên
Nguy cơ mất trí nhớ, Alzheimer do đãng trí, hay quênNguy cơ mất trí nhớ, Alzheimer do đãng trí, hay quên
Nguy cơ mất trí nhớ, Alzheimer do đãng trí, hay quên
 
Sistemas Operativos (Informaciones)
Sistemas Operativos (Informaciones)Sistemas Operativos (Informaciones)
Sistemas Operativos (Informaciones)
 
My final magazine pieces
My final magazine piecesMy final magazine pieces
My final magazine pieces
 

Similar to Design byexceptions

Exception handling
Exception handlingException handling
Exception handlingpooja kumari
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Javaankitgarg_er
 
Lecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxLecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxVishuSaini22
 
exception-handling-in-java.ppt
exception-handling-in-java.pptexception-handling-in-java.ppt
exception-handling-in-java.pptJAYESHRODGE
 
exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2thenmozhip8
 
exceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptexceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptyjrtytyuu
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception HandlingMaqdamYasir
 
Lecture 3.1.1 Try Throw Catch.pptx
Lecture 3.1.1 Try Throw Catch.pptxLecture 3.1.1 Try Throw Catch.pptx
Lecture 3.1.1 Try Throw Catch.pptxsunilsoni446112
 
Exception handling
Exception handlingException handling
Exception handlingMinal Maniar
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overviewBharath K
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptxRDeepa9
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptxRDeepa9
 
Introduction to java exceptions
Introduction to java exceptionsIntroduction to java exceptions
Introduction to java exceptionsSujit Kumar
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allHayomeTakele
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in JavaAnkit Rai
 

Similar to Design byexceptions (20)

Exception handling
Exception handlingException handling
Exception handling
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
 
Lecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxLecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptx
 
Exception handling
Exception handlingException handling
Exception handling
 
exception-handling-in-java.ppt
exception-handling-in-java.pptexception-handling-in-java.ppt
exception-handling-in-java.ppt
 
exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2
 
exceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptexceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.ppt
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
 
Lecture 3.1.1 Try Throw Catch.pptx
Lecture 3.1.1 Try Throw Catch.pptxLecture 3.1.1 Try Throw Catch.pptx
Lecture 3.1.1 Try Throw Catch.pptx
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
Exception handling in .net
Exception handling in .netException handling in .net
Exception handling in .net
 
Introduction to java exceptions
Introduction to java exceptionsIntroduction to java exceptions
Introduction to java exceptions
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
 
How to handle exceptions in Java Technology
How to handle exceptions in Java Technology How to handle exceptions in Java Technology
How to handle exceptions in Java Technology
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 

Recently uploaded

办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一F dds
 
Call Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full NightCall Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 
shot list for my tv series two steps back
shot list for my tv series two steps backshot list for my tv series two steps back
shot list for my tv series two steps back17lcow074
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Narsimha murthy
 
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)jennyeacort
 
3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdf3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdfSwaraliBorhade
 
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full NightCall Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 
Kindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpKindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpmainac1
 
NATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detailNATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detailDesigntroIntroducing
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case StudySophia Viganò
 
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
PORTAFOLIO   2024_  ANASTASIYA  KUDINOVAPORTAFOLIO   2024_  ANASTASIYA  KUDINOVA
PORTAFOLIO 2024_ ANASTASIYA KUDINOVAAnastasiya Kudinova
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
VIP Kolkata Call Girl Gariahat 👉 8250192130 Available With Room
VIP Kolkata Call Girl Gariahat 👉 8250192130  Available With RoomVIP Kolkata Call Girl Gariahat 👉 8250192130  Available With Room
VIP Kolkata Call Girl Gariahat 👉 8250192130 Available With Roomdivyansh0kumar0
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsCharles Obaleagbon
 
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,bhuyansuprit
 
Design Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William VickeryDesign Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William VickeryWilliamVickery6
 

Recently uploaded (20)

办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
 
Call Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full NightCall Girls Satellite 7397865700 Ridhima Hire Me Full Night
Call Girls Satellite 7397865700 Ridhima Hire Me Full Night
 
shot list for my tv series two steps back
shot list for my tv series two steps backshot list for my tv series two steps back
shot list for my tv series two steps back
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
 
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
 
3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdf3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdf
 
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full NightCall Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
 
Kindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpKindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUp
 
NATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detailNATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detail
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case Study
 
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
PORTAFOLIO   2024_  ANASTASIYA  KUDINOVAPORTAFOLIO   2024_  ANASTASIYA  KUDINOVA
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
 
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
 
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
 
VIP Kolkata Call Girl Gariahat 👉 8250192130 Available With Room
VIP Kolkata Call Girl Gariahat 👉 8250192130  Available With RoomVIP Kolkata Call Girl Gariahat 👉 8250192130  Available With Room
VIP Kolkata Call Girl Gariahat 👉 8250192130 Available With Room
 
young call girls in Pandav nagar 🔝 9953056974 🔝 Delhi escort Service
young call girls in Pandav nagar 🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Pandav nagar 🔝 9953056974 🔝 Delhi escort Service
young call girls in Pandav nagar 🔝 9953056974 🔝 Delhi escort Service
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past Questions
 
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,
 
Design Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William VickeryDesign Portfolio - 2024 - William Vickery
Design Portfolio - 2024 - William Vickery
 

Design byexceptions

  • 1. Exceptions Asif Tasleem asiftasleem@gmail.com asiftasleem.blogspot.com http://sa.linkedin.com/in/asiftasleem
  • 2. What is an Exception? • An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.
  • 4. Exceptions Types • Checked Exceptions – These are exceptional conditions that a well-written application should anticipate and recover from. Checked exceptions  are subject to the Catch or Specify Requirement. • Error – These are exceptional conditions that are external to the application, and that the application usually cannot anticipate or recover from. Errors are not subject to the Catch or Specify Requirement.  • Runtime Exceptions – These are exceptional conditions that are internal to the application, and that the application usually cannot anticipate or recover from. These usually indicate programming bugs, such as logic errors or improper use of an API. Runtime exceptions are not subject to the Catch or Specify Requirement.
  • 7. 1: Separating Error-Handling Code from "Regular" Code • Consider the pseudocode method here that reads an entire file into memory. readFile { open the file; determine its size; allocate that much memory; read the file into memory; close the file; }
  • 8. 1: Separating Error-Handling Code from "Regular" Code (Cont.) At first glance, this function seems simple enough, but it ignores all the following potential errors. – What happens if the file can't be opened? – What happens if the length of the file can't be determined? – What happens if enough memory can't be allocated? – What happens if the read fails? – What happens if the file can't be closed?
  • 9. 1: Separating Error-Handling Code from "Regular" Code (Cont.)
  • 10. 1: Separating Error-Handling Code from "Regular" Code (Cont.)
  • 11. 2: Propagating Errors Up the Call Stack
  • 12. 2: Propagating Errors Up the Call Stack (Cont.)
  • 13. 2: Propagating Errors Up the Call Stack (Cont.)
  • 14.  3: Grouping and Differentiating Error Types • As all exceptions thrown within a program are objects, the grouping or categorizing of exceptions is a natural outcome of the class hierarchy.  – A handler can handle only one type of exception. – catch (FileNotFoundException e) { ... – } – A handler can handle a group of exceptions. – catch (IOException e) { ... – } – We could even set up an exception handler that handles any Exception catch (Exception e) { ... – }
  • 16. Exceptions indicate a broken contract • Design by Contract – A software design approach that says that a method represents a contract between the client (the caller of the method) and the class that declares the method. The contract includes preconditions that the client must fulfill and post conditions that the method itself must fulfill. • Precondition – One example of a method with a precondition is the charAt(int index) method of class String. This method requires that the index parameter passed by the client be between 0 and one less than the value returned by invoking length() on the String object. In other words, if the length of a String is 5, the index parameter must be between 0 and 4, inclusive. • Postcondition – The postcondition of String's charAt(int index) method is that its return value will be the character at position index and the string itself will remain unchanged.
  • 17. Unchecked Exceptions The Controversy • Don’t create a subclass of RuntimeException simply because you don't want to be bothered with specifying the exceptions your methods can throw.
  • 18. What to throw? • Exception vs Error – Leave the errors to the big guys. • Checked vs Unchecked exceptions – If you are throwing an exception for an abnormal condition that you feel client programmers should consciously decide how to handle, throw a checked exception. • Define a specific exception class – Don't just throw Exception, for example, with a string message indicating the kind of abnormal condition that caused the exception. 
  • 19. What to throw? (Cont.) • If your method encounters an abnormal condition that it can't handle, it should throw an exception. • Avoid using exceptions to indicate conditions that can reasonably be expected as part of the normal functioning of the method. • If your method discovers that the client has breached its contractual obligations (for example, by passing in bad input data), throw an unchecked exception. • If your method is unable to fulfill its contract, throw either a checked or unchecked exception. • If you are throwing an exception for an abnormal condition that you feel client programmers should consciously decide how to handle, throw a checked exception. • Define or choose an already existing exception class for each kind of abnormal condition that may cause your method to throw an exception.