SlideShare a Scribd company logo
Riktig feilhåndtering

...og ja, checked exceptions er skadelig
Trond Arve Wasskog – JavaZone 2008
0
Feilhåndtering
Exception handling done right (and yes, checked exceptions are not necessary!)
- Trond Arve - BEKK - Confluence

[JavaSpecialists 162] - Exceptions in Java

Unchecked Exceptions — The Controversy (The Java™ Tutorials > Essential
Classes > Exceptions)

java.net: Exception-Handling Antipatterns

java.net: Three Rules for Effective Exception Handling

Java Exceptions Handling

The Art and Craft of Great Software Architecture and Development: Java
Exception Handling Anti-Patterns

Neal Gafter's blog: Closures for Java

Neal Gafter's blog: Removing Language Features?
Exception handling problems in Java, Part I

Exception handling problems in Java, Part II

Bruce Eckel's MindView, Inc: Does Java need Checked Exceptions?

Exceptions in Java: Nothing exceptional about them - Java World

News & Ideas Forum (Closed for new topic posts) - Failure and Exceptions

The Trouble with Checked Exceptions

BEKK forum :: View topic - Håndtering av exceptions - erfaringer/diskusjoner

Thinking Inside a Bigger Box » A Hopeful Idea: The End of Checked
Exceptions?

Should checked exceptions be removed from Java?

The RedirectException - The Daily WTF
Dont Use Exceptions For Flow Control

Exception Patterns

Exception Tunneling

Checked Exceptions Are Of Dubious Value

Octopull/Java: More Exceptional Java

Java theory and practice: The exceptions debate

James Gosling Chimes In on Checked Exceptions

Exception handling - Wikipedia, the free encyclopedia

cat /dev/random » Remove checked exceptions?

Java's checked exceptions were a mistake (and here's what I would like to do
about it)
DOTNET Archives -- November 2000, week 1 (#349)

Java Practices -> Checked versus unchecked exceptions

Java Exception Handling - BEKK - Confluence

Java Exception Handling - BEKK - Confluence

Feilhåndtering - Prosjektkvalitet - Confluence

XO.NET-metoden - Unntakshåndtering - BEKK - Confluence

The Coad Letter: Modeling and Design Edition, Issue 90, Exceptional Strategies

Effective Java Exceptions

cache:DxQf_u_Vue8J:dev2dev.bea.com/lpt/a/541 java exception design
strategies - Google-søk

David Walend's Blog: Design For Exceptions
SwTech.com - Java Design Patterns

Single Sign On - Login

Exception Patterns

Page 2 - Framework Patterns: Exception Handling, Logging, and Tracing

Alexander Klimetschek's Blog : Exception Handling Best Practices Part 1

towards_xcptn_hndling.pdf (application/pdf Object)

Andre's Java Links

JForum - Få slutt på galskapen: Stem "ja" til å fjerne checked exceptions fra
Java

Beware the dangers of generic Exceptions - Java World

Designing with exceptions - Java World
Forward - Tips and Guidelines for Programming Java GUI Applications

warning unchecked exception - Google-søk

Exception (Java 2 Platform SE v1.4.2)

LISTSERV 15.0 - RMI-USERS Archives

Google Answers: The origin of checked exceptions

Java (programming language) - Wikipedia, the free encyclopedia

Hacking Architect : Weblog

Old News: Java Checked vs. Unchecked Exceptions « Bees Are Social By Nature

Opinion: Exception Handling Debate is Back

Manageability - The Exception Debate: Why Gosling and Hejlsberg are Both In
Error
Mistaeks I Hav Made: Generic Throws: Another Little Java Idiom

DataAccessException.gif (GIF Image, 916x397 pixels)

Antonio Goncalves' Weblog

A Test-Driven Exploration of the Advanced Features of EJB 3.0
Dårlig feilhåndtering er vanlig
1972




       Return
       Codes
1964




        On Error
       Exceptions
Return
                     Codes




         On Error
        Exceptions




1964   1972          1983     1992 1995   2001
Return
                     Codes




                              Exceptions


         On Error
        Exceptions




1964   1972          1983             1992 1995   2001
Return
                     Codes
                                            Checked
                                           Exceptions


                              Exceptions


         On Error
        Exceptions




1964   1972          1983             1992 1995         2001
Return
                     Codes
                                            Checked
                                           Exceptions


                              Exceptions
                                                    Exceptions
         On Error
        Exceptions




1964   1972          1983             1992 1995         2001
Java Exceptions


                  Throwable
Java Exceptions


                  Throwable




                                 Exception




                     Checked
                    Exceptions
Java Exceptions


                  Throwable




                                 Exception




                                             Runtime
                     Checked
                                             Exception
                    Exceptions



                                             Unchecked
                                             Exceptions
Java Exceptions


                   Throwable




       Error                      Exception




      VM Errors                               Runtime
                      Checked
     (Unchecked)                              Exception
                     Exceptions



                                              Unchecked
                                              Exceptions
Et alternativt design


                        Throwable




                          <interface>
        Error             Unchecked                  Exception
                           Exception




       VM Errors                        Unchecked                 Checked
                                        Exceptions               Exceptions
1
Hvem bryr seg om feilhåndtering?
Brukeren er opptatt av at en feil har
oppstått og at situasjonen er håndtert,
      ikke hva som har skjedd
Forretningen forstår funksjonelle feil og
         vil unngå kritiske feil
Drift vil vite hva de skal gjøre med feilen
Utviklere vil vite hva som har skjedd, hvor,
 når, hvorfor, hvem, tilstand og kontekst
Feilhåndtering har ulike interessenter med
          sine spesifikke behov


Typisk er få representert som kravstillere
2
Feilhåndtering
Hva kan man gjøre når en feil oppstår?
Ignorere?
Håndtere?
Prøv igjen?
Prøv et alternativ?
Avslutte forespørselen
Hvor skal feil håndteres?
Lokal feilhåndtering
Sentral feilhåndtering
De aller fleste applikasjoner er tjent med
           sentral feilhåndtering
Feilhåndtering vs feilretting
Hva skjer om en
annen Exception
   eller Error
    kastes?
Er det viktig at
operasjonen eller
 applikasjonen
   fungerer?
Feilhåndtering
  sørger for
 konsistens
Feilhåndtering er kritisk for applikasjonen
Automatisert feilretting er ofte
komplekst, kostbart og risikabelt
Feilhåndtering er viktigere enn feilretting
3
Tre feiltyper
Application Exception
System Exception
Programming Exception

        a.k.a
  RuntimeException
Type          Håndter   Feilfiks og   Prøv igjen?
                        utrulling
Application   Mulig     Nei           Nei
Exception



System        Nei       Nei           Mulig
Exception



Programming   Nei       Ja            Nei
Exception
4
Overordnet Design
Lettvekts exception-hierarki - Distribuert
Felles exception-klasser med feilkode - Sentralisert



                             java.lang
                         RuntimeException



                         AbstractException
                              - Long id




        ApplicationException                SystemException
Hybrid – Sentrale exception-klasser, distribuert hierarki

                             java.lang
                         RuntimeException



                        AbstractException
                             - Long id




        ApplicationException                SystemException




                dd                             dd
       <Application Exceptions>         <System Exceptions>
AbstractException
          -Long id
      - Map context
 -----------------------------
addContext(key, value)
Rammeverk = Distribuert

Applikasjon = Sentralisert
5
Checked Exceptions
Ondskapens akse


                   Jim                     James                   Ann
                  Waldo                    Gosling                Wollrath



There was a time when Oak and the earliest version of Java did not have
checked exceptions. Exception handling was advisory, and it was an
unsafe world out there. It was our group (Jim Waldo and I in particular :-)
that recommended that there be exceptions checked by the compiler. Jim
was quite persuasive in his arguments, telling of a world where robust
code would reign. After some consideration, Java was retooled to have
checked exceptions. Only those exceptions for which there was no
recovery or reflect application errors would be unchecked (e.g.,
OutOfMemoryError, NullPointerException respectively). And the world
was safe again
-- Ann Wollrath
http://archives.java.sun.com/cgi-bin/wa?A2=ind9901&L=RMI-USERS&P=R25037
Ringbærerne

              Item 58: Use chekced exceptions for recoverable conditions
              and runtime exceptions for programming errors

              Item 59: Avoid unnecessary use of checked exceptions

              -- Joshua Bloch

          I believe the language could be simplified by treating all
          exception types as unchecked without breaking existing
          programs. This could also result in a simplification of future
          language extensions and APIs. But would the language and
          platform be better off without checked exceptions?
          -- Neil Gafter

          The overhead of checked exceptions was having the opposite
          effect of what was intended, something that can happen when
          you experiment (and I now believe that checked exceptions were
          an experiment based on what someone thought was a good idea,
          and which I believed was a good idea until recently).
          -- Bruce Eckel
Source: http://java.net/pub/pq/163
“Checked exceptions are gold.
Developers that don't like them are
 those that are too lazy to actually
     think about error cases.”



http://www.javaworld.com/javaforums/showflat.php?Cat=0&Number=35228&Main=2629
“Were all exceptions unchecked,
   no exceptions would be caught
    until the corresponding bugs
   began to present themselves.”


http://www.javaworld.com/javaforums/showflat.php?Cat=0&Number=35228&Main=2629
“Checked exceptions seem like a
    really good idea at first…

  However, the kind of code you
must write around these things and
   the common phenomenon of
"swallowed" exceptions begins to
   suggest there's a problem. ”
   http://www.mindview.net/Etc/Discussions/CheckedExceptions
“I am so tired of all the comments
   singing the praise of checked
exceptions on a theoretical basis. I
 don’t care about what’s good in
              theory!”


   http://www.javaworld.com/community/?q=comment/reply/1128
“The HibernateException, which wraps most of
     the errors that can occur in a Hibernate
persistence layer, is an unchecked exception
  (it wasn't in older versions of Hibernate).

   In our opinion, we shouldn't force the
     application developer to catch an
 unrecoverable exception at a low layer. In
most systems, unchecked and fatal exceptions
 are handled in one of the first frames of the
              method call stack”
 http://www.hibernate.org/hib_docs/reference/en/html/transactions.html
Checked exceptions
 forurenser APIet
Checked exceptions fører til
unnamanøvre som forpester
         koden
Checked exceptions påtvinger
   lokal ”feilhåndtering”
java.text.ParseException

  java.net.MalformedURLException

java.lang.CloneNotSupportedException
Checked exceptions kan brukes
når klienten alltid både kan og må
          håndtere feilen.
God feilhåndtering er viktig

    Exceptions er bra

Dokumenter feilsituasjoner
Skal kompilatoren påtvinge
      feilhåndtering?
Checked exceptions påfører
  applikasjoner stor skade

Checked exceptions bør fjernes
6
Slik, ikke slik!
Ikke bruk exceptions for normal
       forretningslogikk
Bruk eksisterende exceptions
IllegalStateException
UnsupportedOperationException
   IllegalArgumentException
   NoSuchElementException
       NullPointerException
Ikke sluk exceptions
Fallgruver med try-catch-finally
Dokumenter exceptions
Russisk kone
ERROR [btpool0-3] JDBCExceptionReporter.logExceptions(78) | Violation
of unique constraint $$: duplicate value(s) for column(s) $$: SYS_CT_88 in statement [insert into
app_user (id, account_expired, account_locked, address, city, country, postal_code, province,
credentials_expired, email, account_enabled, first_name, last_name, password, password_hint, phone_number,
username, version, website) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
org.springframework.dao.DataIntegrityViolationException: could not insert: [edu.ksu.model.User];   nested
exception is        org.hibernate.exception.ConstraintViolationException: could not insert: [edu.ksu.model.User]
        at
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:
624)
        at
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
        at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
        at
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
        at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:744)
<snip/>
Caused by:          org.hibernate.exception.ConstraintViolationException: could not insert: [edu.ksu.model.User]
          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
<snip/>
Caused by: java.sql.SQLException: Violation of unique constraint                                        $$:
duplicate value(s) for column(s) $$: SYS_CT_88 in statement [insert into app_user (id, account_expired,
account_locked, address, city, country, postal_code, province, credentials_expired, email, account_enabled,
first_name, last_name, password, password_hint, phone_number, username, version, website) values (null, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
        at org.hsqldb.jdbc.Util.throwError(Unknown Source)
        at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
        at
org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
        at
org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
        at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:33)
        ... 143 more
Unngå både logging og kasting
Drift trenger unik feilkode for å
        identifisere feilen
Utviklere trenger unik instans-ID
     for å identifisere feilen
Exceptions skal også testes
Bruk stubber for testing av
   eksterne systemer
<Stub>
                              Fagsystem A



 <interface>    <interface>
Fagsystem A    Fagsystem A




                              Fagsystem A
Gjør logging enkelt
Gjør logging enkelt
Legg til kontekst der feilen oppstår
Takk for oppmerksomheten!



trond.arve.wasskog[at]bekk.no
                               BEKK CONSULTING AS
  SKUR 39, VIPPETANGEN. P.O. BOX 134 SENTRUM, 0102 OSLO, NORWAY. WWW.BEKK.NO

More Related Content

Viewers also liked

搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題
搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題
搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題
teddysoft
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
ankitgarg_er
 
Download5
Download5Download5
Results of questionnaire
Results of questionnaireResults of questionnaire
Results of questionnaire
shumi26
 
Medical dressings - Asia
Medical dressings - AsiaMedical dressings - Asia
Medical dressings - Asia
Market Research & Data Services
 
Download4
Download4Download4
Power electronical testing services
Power electronical testing servicesPower electronical testing services
Power electronical testing services
Power Electronical
 
Arkitektur på vondt og godt
Arkitektur på vondt og godtArkitektur på vondt og godt
Arkitektur på vondt og godt
ilmyggo
 
Agile Isn't What You Do (It's What You Think)
Agile Isn't What You Do (It's What You Think)Agile Isn't What You Do (It's What You Think)
Agile Isn't What You Do (It's What You Think)
Derek W. Wade
 
Week8
Week8Week8
Bearing markets in americas
Bearing markets in americasBearing markets in americas
Bearing markets in americas
Market Research & Data Services
 
P&O Session 2
P&O Session 2P&O Session 2
P&O Session 2
Sven Charleer
 
Library
LibraryLibrary
Library
vjauregui
 

Viewers also liked (13)

搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題
搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題
搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
 
Download5
Download5Download5
Download5
 
Results of questionnaire
Results of questionnaireResults of questionnaire
Results of questionnaire
 
Medical dressings - Asia
Medical dressings - AsiaMedical dressings - Asia
Medical dressings - Asia
 
Download4
Download4Download4
Download4
 
Power electronical testing services
Power electronical testing servicesPower electronical testing services
Power electronical testing services
 
Arkitektur på vondt og godt
Arkitektur på vondt og godtArkitektur på vondt og godt
Arkitektur på vondt og godt
 
Agile Isn't What You Do (It's What You Think)
Agile Isn't What You Do (It's What You Think)Agile Isn't What You Do (It's What You Think)
Agile Isn't What You Do (It's What You Think)
 
Week8
Week8Week8
Week8
 
Bearing markets in americas
Bearing markets in americasBearing markets in americas
Bearing markets in americas
 
P&O Session 2
P&O Session 2P&O Session 2
P&O Session 2
 
Library
LibraryLibrary
Library
 

Similar to Riktig feilhåndtering (og ja, checked exceptions er skadelige)

Introduction to java exceptions
Introduction to java exceptionsIntroduction to java exceptions
Introduction to java exceptions
Sujit Kumar
 
Vb.net session 12
Vb.net session 12Vb.net session 12
Vb.net session 12
Niit Care
 
Sample
SampleSample
Sample
guest6e4b7c
 
ruby_exceptions.pdf
ruby_exceptions.pdfruby_exceptions.pdf
ruby_exceptions.pdf
guest6e4b7c
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
guest0046de
 
Sample
SampleSample
Sample
guest6e4b7c
 
Sample
SampleSample
Sample
guest6e4b7c
 
Sample
SampleSample
Sample
guest6e4b7c
 
Sample
SampleSample
Sample
guest6e4b7c
 
ruby_exceptions.pdf
ruby_exceptions.pdfruby_exceptions.pdf
ruby_exceptions.pdf
guest6e4b7c
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
guest0046de
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
guest0046de
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
guest6e4b7c
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
guest0046de
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
guest0046de
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
guest6e4b7c
 
Sample
SampleSample
Sample
guest6e4b7c
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
guest6e4b7c
 
Sample
SampleSample
Sample
guest6e4b7c
 
ruby_exceptions.pdf
ruby_exceptions.pdfruby_exceptions.pdf
ruby_exceptions.pdf
guest6e4b7c
 

Similar to Riktig feilhåndtering (og ja, checked exceptions er skadelige) (20)

Introduction to java exceptions
Introduction to java exceptionsIntroduction to java exceptions
Introduction to java exceptions
 
Vb.net session 12
Vb.net session 12Vb.net session 12
Vb.net session 12
 
Sample
SampleSample
Sample
 
ruby_exceptions.pdf
ruby_exceptions.pdfruby_exceptions.pdf
ruby_exceptions.pdf
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
 
Sample
SampleSample
Sample
 
Sample
SampleSample
Sample
 
Sample
SampleSample
Sample
 
Sample
SampleSample
Sample
 
ruby_exceptions.pdf
ruby_exceptions.pdfruby_exceptions.pdf
ruby_exceptions.pdf
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
 
Sample
SampleSample
Sample
 
Ruby Exceptions
Ruby ExceptionsRuby Exceptions
Ruby Exceptions
 
Sample
SampleSample
Sample
 
ruby_exceptions.pdf
ruby_exceptions.pdfruby_exceptions.pdf
ruby_exceptions.pdf
 

More from ilmyggo

Software Kollapser Under Sin Egen Vekt JavaZone 2023
Software Kollapser Under Sin Egen Vekt JavaZone 2023Software Kollapser Under Sin Egen Vekt JavaZone 2023
Software Kollapser Under Sin Egen Vekt JavaZone 2023
ilmyggo
 
GodeMinerTilSlettSpill-JavaZone.pdf
GodeMinerTilSlettSpill-JavaZone.pdfGodeMinerTilSlettSpill-JavaZone.pdf
GodeMinerTilSlettSpill-JavaZone.pdf
ilmyggo
 
JavaZone 2021: Året da åpen kildekode ble diskutert på Stortinget! av Trond A...
JavaZone 2021: Året da åpen kildekode ble diskutert på Stortinget! av Trond A...JavaZone 2021: Året da åpen kildekode ble diskutert på Stortinget! av Trond A...
JavaZone 2021: Året da åpen kildekode ble diskutert på Stortinget! av Trond A...
ilmyggo
 
Lov og rett i skyen JavaZone 2018
Lov og rett i skyen JavaZone 2018Lov og rett i skyen JavaZone 2018
Lov og rett i skyen JavaZone 2018
ilmyggo
 
Bekk Teknologiradar 2018 - Modige ledere
Bekk Teknologiradar 2018 - Modige ledereBekk Teknologiradar 2018 - Modige ledere
Bekk Teknologiradar 2018 - Modige ledere
ilmyggo
 
Atom Feeds Gruser JMS
Atom Feeds Gruser JMSAtom Feeds Gruser JMS
Atom Feeds Gruser JMS
ilmyggo
 
Tis not agile
Tis not agileTis not agile
Tis not agile
ilmyggo
 
Driftbarhet - Steg mot smidig drift, JavaZone 2010
Driftbarhet - Steg mot smidig drift, JavaZone 2010Driftbarhet - Steg mot smidig drift, JavaZone 2010
Driftbarhet - Steg mot smidig drift, JavaZone 2010
ilmyggo
 

More from ilmyggo (8)

Software Kollapser Under Sin Egen Vekt JavaZone 2023
Software Kollapser Under Sin Egen Vekt JavaZone 2023Software Kollapser Under Sin Egen Vekt JavaZone 2023
Software Kollapser Under Sin Egen Vekt JavaZone 2023
 
GodeMinerTilSlettSpill-JavaZone.pdf
GodeMinerTilSlettSpill-JavaZone.pdfGodeMinerTilSlettSpill-JavaZone.pdf
GodeMinerTilSlettSpill-JavaZone.pdf
 
JavaZone 2021: Året da åpen kildekode ble diskutert på Stortinget! av Trond A...
JavaZone 2021: Året da åpen kildekode ble diskutert på Stortinget! av Trond A...JavaZone 2021: Året da åpen kildekode ble diskutert på Stortinget! av Trond A...
JavaZone 2021: Året da åpen kildekode ble diskutert på Stortinget! av Trond A...
 
Lov og rett i skyen JavaZone 2018
Lov og rett i skyen JavaZone 2018Lov og rett i skyen JavaZone 2018
Lov og rett i skyen JavaZone 2018
 
Bekk Teknologiradar 2018 - Modige ledere
Bekk Teknologiradar 2018 - Modige ledereBekk Teknologiradar 2018 - Modige ledere
Bekk Teknologiradar 2018 - Modige ledere
 
Atom Feeds Gruser JMS
Atom Feeds Gruser JMSAtom Feeds Gruser JMS
Atom Feeds Gruser JMS
 
Tis not agile
Tis not agileTis not agile
Tis not agile
 
Driftbarhet - Steg mot smidig drift, JavaZone 2010
Driftbarhet - Steg mot smidig drift, JavaZone 2010Driftbarhet - Steg mot smidig drift, JavaZone 2010
Driftbarhet - Steg mot smidig drift, JavaZone 2010
 

Recently uploaded

GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 

Recently uploaded (20)

GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 

Riktig feilhåndtering (og ja, checked exceptions er skadelige)

  • 1. Riktig feilhåndtering ...og ja, checked exceptions er skadelig Trond Arve Wasskog – JavaZone 2008
  • 3. Exception handling done right (and yes, checked exceptions are not necessary!) - Trond Arve - BEKK - Confluence [JavaSpecialists 162] - Exceptions in Java Unchecked Exceptions — The Controversy (The Java™ Tutorials > Essential Classes > Exceptions) java.net: Exception-Handling Antipatterns java.net: Three Rules for Effective Exception Handling Java Exceptions Handling The Art and Craft of Great Software Architecture and Development: Java Exception Handling Anti-Patterns Neal Gafter's blog: Closures for Java Neal Gafter's blog: Removing Language Features?
  • 4. Exception handling problems in Java, Part I Exception handling problems in Java, Part II Bruce Eckel's MindView, Inc: Does Java need Checked Exceptions? Exceptions in Java: Nothing exceptional about them - Java World News & Ideas Forum (Closed for new topic posts) - Failure and Exceptions The Trouble with Checked Exceptions BEKK forum :: View topic - Håndtering av exceptions - erfaringer/diskusjoner Thinking Inside a Bigger Box » A Hopeful Idea: The End of Checked Exceptions? Should checked exceptions be removed from Java? The RedirectException - The Daily WTF
  • 5. Dont Use Exceptions For Flow Control Exception Patterns Exception Tunneling Checked Exceptions Are Of Dubious Value Octopull/Java: More Exceptional Java Java theory and practice: The exceptions debate James Gosling Chimes In on Checked Exceptions Exception handling - Wikipedia, the free encyclopedia cat /dev/random » Remove checked exceptions? Java's checked exceptions were a mistake (and here's what I would like to do about it)
  • 6. DOTNET Archives -- November 2000, week 1 (#349) Java Practices -> Checked versus unchecked exceptions Java Exception Handling - BEKK - Confluence Java Exception Handling - BEKK - Confluence Feilhåndtering - Prosjektkvalitet - Confluence XO.NET-metoden - Unntakshåndtering - BEKK - Confluence The Coad Letter: Modeling and Design Edition, Issue 90, Exceptional Strategies Effective Java Exceptions cache:DxQf_u_Vue8J:dev2dev.bea.com/lpt/a/541 java exception design strategies - Google-søk David Walend's Blog: Design For Exceptions
  • 7. SwTech.com - Java Design Patterns Single Sign On - Login Exception Patterns Page 2 - Framework Patterns: Exception Handling, Logging, and Tracing Alexander Klimetschek's Blog : Exception Handling Best Practices Part 1 towards_xcptn_hndling.pdf (application/pdf Object) Andre's Java Links JForum - Få slutt på galskapen: Stem "ja" til å fjerne checked exceptions fra Java Beware the dangers of generic Exceptions - Java World Designing with exceptions - Java World
  • 8. Forward - Tips and Guidelines for Programming Java GUI Applications warning unchecked exception - Google-søk Exception (Java 2 Platform SE v1.4.2) LISTSERV 15.0 - RMI-USERS Archives Google Answers: The origin of checked exceptions Java (programming language) - Wikipedia, the free encyclopedia Hacking Architect : Weblog Old News: Java Checked vs. Unchecked Exceptions « Bees Are Social By Nature Opinion: Exception Handling Debate is Back Manageability - The Exception Debate: Why Gosling and Hejlsberg are Both In Error
  • 9. Mistaeks I Hav Made: Generic Throws: Another Little Java Idiom DataAccessException.gif (GIF Image, 916x397 pixels) Antonio Goncalves' Weblog A Test-Driven Exploration of the Advanced Features of EJB 3.0
  • 11. 1972 Return Codes
  • 12. 1964 On Error Exceptions
  • 13. Return Codes On Error Exceptions 1964 1972 1983 1992 1995 2001
  • 14. Return Codes Exceptions On Error Exceptions 1964 1972 1983 1992 1995 2001
  • 15. Return Codes Checked Exceptions Exceptions On Error Exceptions 1964 1972 1983 1992 1995 2001
  • 16. Return Codes Checked Exceptions Exceptions Exceptions On Error Exceptions 1964 1972 1983 1992 1995 2001
  • 17. Java Exceptions Throwable
  • 18. Java Exceptions Throwable Exception Checked Exceptions
  • 19. Java Exceptions Throwable Exception Runtime Checked Exception Exceptions Unchecked Exceptions
  • 20. Java Exceptions Throwable Error Exception VM Errors Runtime Checked (Unchecked) Exception Exceptions Unchecked Exceptions
  • 21. Et alternativt design Throwable <interface> Error Unchecked Exception Exception VM Errors Unchecked Checked Exceptions Exceptions
  • 22. 1 Hvem bryr seg om feilhåndtering?
  • 23. Brukeren er opptatt av at en feil har oppstått og at situasjonen er håndtert, ikke hva som har skjedd
  • 24. Forretningen forstår funksjonelle feil og vil unngå kritiske feil
  • 25. Drift vil vite hva de skal gjøre med feilen
  • 26. Utviklere vil vite hva som har skjedd, hvor, når, hvorfor, hvem, tilstand og kontekst
  • 27. Feilhåndtering har ulike interessenter med sine spesifikke behov Typisk er få representert som kravstillere
  • 29. Hva kan man gjøre når en feil oppstår?
  • 35. Hvor skal feil håndteres?
  • 38. De aller fleste applikasjoner er tjent med sentral feilhåndtering
  • 40.
  • 41. Hva skjer om en annen Exception eller Error kastes?
  • 42.
  • 43. Er det viktig at operasjonen eller applikasjonen fungerer?
  • 44. Feilhåndtering sørger for konsistens
  • 45. Feilhåndtering er kritisk for applikasjonen
  • 46. Automatisert feilretting er ofte komplekst, kostbart og risikabelt
  • 47. Feilhåndtering er viktigere enn feilretting
  • 51. Programming Exception a.k.a RuntimeException
  • 52. Type Håndter Feilfiks og Prøv igjen? utrulling Application Mulig Nei Nei Exception System Nei Nei Mulig Exception Programming Nei Ja Nei Exception
  • 55. Felles exception-klasser med feilkode - Sentralisert java.lang RuntimeException AbstractException - Long id ApplicationException SystemException
  • 56. Hybrid – Sentrale exception-klasser, distribuert hierarki java.lang RuntimeException AbstractException - Long id ApplicationException SystemException dd dd <Application Exceptions> <System Exceptions>
  • 57. AbstractException -Long id - Map context ----------------------------- addContext(key, value)
  • 60.
  • 61. Ondskapens akse Jim James Ann Waldo Gosling Wollrath There was a time when Oak and the earliest version of Java did not have checked exceptions. Exception handling was advisory, and it was an unsafe world out there. It was our group (Jim Waldo and I in particular :-) that recommended that there be exceptions checked by the compiler. Jim was quite persuasive in his arguments, telling of a world where robust code would reign. After some consideration, Java was retooled to have checked exceptions. Only those exceptions for which there was no recovery or reflect application errors would be unchecked (e.g., OutOfMemoryError, NullPointerException respectively). And the world was safe again -- Ann Wollrath http://archives.java.sun.com/cgi-bin/wa?A2=ind9901&L=RMI-USERS&P=R25037
  • 62. Ringbærerne Item 58: Use chekced exceptions for recoverable conditions and runtime exceptions for programming errors Item 59: Avoid unnecessary use of checked exceptions -- Joshua Bloch I believe the language could be simplified by treating all exception types as unchecked without breaking existing programs. This could also result in a simplification of future language extensions and APIs. But would the language and platform be better off without checked exceptions? -- Neil Gafter The overhead of checked exceptions was having the opposite effect of what was intended, something that can happen when you experiment (and I now believe that checked exceptions were an experiment based on what someone thought was a good idea, and which I believed was a good idea until recently). -- Bruce Eckel
  • 64. “Checked exceptions are gold. Developers that don't like them are those that are too lazy to actually think about error cases.” http://www.javaworld.com/javaforums/showflat.php?Cat=0&Number=35228&Main=2629
  • 65. “Were all exceptions unchecked, no exceptions would be caught until the corresponding bugs began to present themselves.” http://www.javaworld.com/javaforums/showflat.php?Cat=0&Number=35228&Main=2629
  • 66. “Checked exceptions seem like a really good idea at first… However, the kind of code you must write around these things and the common phenomenon of "swallowed" exceptions begins to suggest there's a problem. ” http://www.mindview.net/Etc/Discussions/CheckedExceptions
  • 67. “I am so tired of all the comments singing the praise of checked exceptions on a theoretical basis. I don’t care about what’s good in theory!” http://www.javaworld.com/community/?q=comment/reply/1128
  • 68. “The HibernateException, which wraps most of the errors that can occur in a Hibernate persistence layer, is an unchecked exception (it wasn't in older versions of Hibernate). In our opinion, we shouldn't force the application developer to catch an unrecoverable exception at a low layer. In most systems, unchecked and fatal exceptions are handled in one of the first frames of the method call stack” http://www.hibernate.org/hib_docs/reference/en/html/transactions.html
  • 70. Checked exceptions fører til unnamanøvre som forpester koden
  • 71. Checked exceptions påtvinger lokal ”feilhåndtering”
  • 73. Checked exceptions kan brukes når klienten alltid både kan og må håndtere feilen.
  • 74. God feilhåndtering er viktig Exceptions er bra Dokumenter feilsituasjoner
  • 75. Skal kompilatoren påtvinge feilhåndtering?
  • 76.
  • 77.
  • 78. Checked exceptions påfører applikasjoner stor skade Checked exceptions bør fjernes
  • 80. Ikke bruk exceptions for normal forretningslogikk
  • 81.
  • 83. IllegalStateException UnsupportedOperationException IllegalArgumentException NoSuchElementException NullPointerException
  • 85.
  • 86.
  • 87.
  • 88.
  • 90.
  • 91.
  • 92.
  • 93.
  • 95.
  • 96.
  • 98.
  • 99. ERROR [btpool0-3] JDBCExceptionReporter.logExceptions(78) | Violation of unique constraint $$: duplicate value(s) for column(s) $$: SYS_CT_88 in statement [insert into app_user (id, account_expired, account_locked, address, city, country, postal_code, province, credentials_expired, email, account_enabled, first_name, last_name, password, password_hint, phone_number, username, version, website) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? org.springframework.dao.DataIntegrityViolationException: could not insert: [edu.ksu.model.User]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [edu.ksu.model.User] at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java: 624) at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424) at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:744) <snip/> Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [edu.ksu.model.User] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) <snip/> Caused by: java.sql.SQLException: Violation of unique constraint $$: duplicate value(s) for column(s) $$: SYS_CT_88 in statement [insert into app_user (id, account_expired, account_locked, address, city, country, postal_code, province, credentials_expired, email, account_enabled, first_name, last_name, password, password_hint, phone_number, username, version, website) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)] at org.hsqldb.jdbc.Util.throwError(Unknown Source) at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101) at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:33) ... 143 more
  • 100. Unngå både logging og kasting
  • 101.
  • 102. Drift trenger unik feilkode for å identifisere feilen
  • 103.
  • 104. Utviklere trenger unik instans-ID for å identifisere feilen
  • 105.
  • 107.
  • 108.
  • 109. Bruk stubber for testing av eksterne systemer
  • 110. <Stub> Fagsystem A <interface> <interface> Fagsystem A Fagsystem A Fagsystem A
  • 113. Legg til kontekst der feilen oppstår
  • 114. Takk for oppmerksomheten! trond.arve.wasskog[at]bekk.no BEKK CONSULTING AS SKUR 39, VIPPETANGEN. P.O. BOX 134 SENTRUM, 0102 OSLO, NORWAY. WWW.BEKK.NO