Riktig feilhåndtering (og ja, checked exceptions er skadelige)
-
Upload
ilmyggo -
Category
Technology
-
view
241 -
download
4
Transcript of Riktig feilhåndtering (og ja, checked exceptions er skadelige)
![Page 1: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/1.jpg)
Riktig feilhåndtering
...og ja, checked exceptions er skadelig
Trond Arve Wasskog – JavaZone 2008
![Page 2: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/2.jpg)
0Feilhåndtering
![Page 3: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/3.jpg)
� 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?
![Page 4: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/4.jpg)
� 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
![Page 5: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/5.jpg)
� 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)
![Page 6: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/6.jpg)
� 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
![Page 7: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/7.jpg)
� 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
![Page 8: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/8.jpg)
� 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
![Page 9: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/9.jpg)
� 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
![Page 10: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/10.jpg)
Dårlig feilhåndtering er vanlig
![Page 11: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/11.jpg)
1972
ReturnCodes
![Page 12: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/12.jpg)
1964
On ErrorExceptions
![Page 13: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/13.jpg)
1964 1972 1983 1992 1995 2001
ReturnCodes
On ErrorExceptions
![Page 14: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/14.jpg)
1964 1972 1983 1992 1995 2001
ReturnCodes
On ErrorExceptions
Exceptions
![Page 15: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/15.jpg)
1964 1972 1983 1992 1995 2001
ReturnCodes
On ErrorExceptions
Exceptions
CheckedExceptions
![Page 16: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/16.jpg)
1964 1972 1983 1992 1995 2001
ReturnCodes
On ErrorExceptions
Exceptions
CheckedExceptions
Exceptions
![Page 17: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/17.jpg)
Java Exceptions
Throwable
![Page 18: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/18.jpg)
Java Exceptions
Throwable
Exception
Checked
Exceptions
![Page 19: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/19.jpg)
Java Exceptions
Throwable
Exception
Runtime
ExceptionChecked
Exceptions
Unchecked
Exceptions
![Page 20: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/20.jpg)
Java Exceptions
Throwable
Error Exception
Runtime
ExceptionVM Errors
(Unchecked)Checked
Exceptions
Unchecked
Exceptions
![Page 21: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/21.jpg)
Et alternativt design
Throwable
Error Exception
VM Errors
<interface>
Unchecked
Exception
Unchecked
Exceptions
Checked
Exceptions
![Page 22: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/22.jpg)
1Hvem bryr seg om feilhåndtering?
![Page 23: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/23.jpg)
Brukeren er opptatt av at en feil har oppstått og at situasjonen er håndtert,
ikke hva som har skjedd
![Page 24: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/24.jpg)
Forretningen forstår funksjonelle feil og vil unngå kritiske feil
![Page 25: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/25.jpg)
Drift vil vite hva de skal gjøre med feilen
![Page 26: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/26.jpg)
Utviklere vil vite hva som har skjedd, hvor, når, hvorfor, hvem, tilstand og kontekst
![Page 27: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/27.jpg)
Feilhåndtering har ulike interessenter med sine spesifikke behov
Typisk er få representert som kravstillere
![Page 28: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/28.jpg)
2Feilhåndtering
![Page 29: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/29.jpg)
Hva kan man gjøre når en feil oppstår?
![Page 30: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/30.jpg)
Ignorere?
![Page 31: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/31.jpg)
Håndtere?
![Page 32: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/32.jpg)
Prøv igjen?
![Page 33: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/33.jpg)
Prøv et alternativ?
![Page 34: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/34.jpg)
Avslutte forespørselen
![Page 35: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/35.jpg)
Hvor skal feil håndteres?
![Page 36: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/36.jpg)
Lokal feilhåndtering
![Page 37: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/37.jpg)
Sentral feilhåndtering
![Page 38: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/38.jpg)
De aller fleste applikasjoner er tjent med sentral feilhåndtering
![Page 39: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/39.jpg)
Feilhåndtering vs feilretting
![Page 40: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/40.jpg)
![Page 41: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/41.jpg)
Hva skjer om en annen Exception
eller Error kastes?
![Page 42: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/42.jpg)
![Page 43: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/43.jpg)
Er det viktig at operasjonen eller
applikasjonen fungerer?
![Page 44: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/44.jpg)
Feilhåndtering sørger for konsistens
![Page 45: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/45.jpg)
Feilhåndtering er kritisk for applikasjonen
![Page 46: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/46.jpg)
Automatisert feilretting er ofte komplekst, kostbart og risikabelt
![Page 47: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/47.jpg)
Feilhåndtering er viktigere enn feilretting
![Page 48: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/48.jpg)
3Tre feiltyper
![Page 49: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/49.jpg)
Application Exception
![Page 50: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/50.jpg)
System Exception
![Page 51: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/51.jpg)
Programming Exception
a.k.aRuntimeException
![Page 52: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/52.jpg)
Type Håndter Feilfiks og
utrulling
Prøv igjen?
Application
Exception
Mulig Nei Nei
System
Exception
Nei Nei Mulig
Programming
Exception
Nei Ja Nei
![Page 53: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/53.jpg)
4Overordnet Design
![Page 54: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/54.jpg)
Lettvekts exception-hierarki - Distribuert
![Page 55: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/55.jpg)
Felles exception-klasser med feilkode - Sentralisert
AbstractException- Long id
ApplicationException SystemException
java.lang
RuntimeException
![Page 56: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/56.jpg)
Hybrid – Sentrale exception-klasser, distribuert hierarki
AbstractException- Long id
ApplicationException SystemException
java.lang
RuntimeException
dd<System Exceptions>
dd<Application Exceptions>
![Page 57: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/57.jpg)
AbstractException-Long id
- Map context
-----------------------------
addContext(key, value)
![Page 58: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/58.jpg)
Rammeverk = Distribuert
Applikasjon = Sentralisert
![Page 59: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/59.jpg)
5Checked Exceptions
![Page 60: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/60.jpg)
![Page 61: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/61.jpg)
Ondskapens akse
JimWaldo
JamesGosling
Ann 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 norecovery or reflect application errors would be unchecked (e.g.,OutOfMemoryError, NullPointerException respectively). And the world was safe again
-- Ann Wollrathhttp://archives.java.sun.com/cgi-bin/wa?A2=ind9901&L=RMI-USERS&P=R25037
![Page 62: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/62.jpg)
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
![Page 63: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/63.jpg)
Source: http://java.net/pub/pq/163
![Page 64: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/64.jpg)
“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
![Page 65: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/65.jpg)
“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
![Page 66: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/66.jpg)
“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
![Page 67: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/67.jpg)
“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
![Page 68: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/68.jpg)
“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
![Page 69: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/69.jpg)
Checked exceptions forurenser APIet
![Page 70: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/70.jpg)
Checked exceptions fører til unnamanøvre som forpester
koden
![Page 71: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/71.jpg)
Checked exceptions påtvinger lokal ”feilhåndtering”
![Page 72: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/72.jpg)
java.text.ParseException
java.net.MalformedURLException
java.lang.CloneNotSupportedException
![Page 73: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/73.jpg)
Checked exceptions kan brukes når klienten alltid både kan og må
håndtere feilen.
![Page 74: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/74.jpg)
God feilhåndtering er viktig
Exceptions er bra
Dokumenter feilsituasjoner
![Page 75: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/75.jpg)
Skal kompilatoren påtvinge feilhåndtering?
![Page 76: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/76.jpg)
![Page 77: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/77.jpg)
![Page 78: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/78.jpg)
Checked exceptions påfører applikasjoner stor skade
Checked exceptions bør fjernes
![Page 79: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/79.jpg)
6Slik, ikke slik!
![Page 80: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/80.jpg)
Ikke bruk exceptions for normal forretningslogikk
![Page 81: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/81.jpg)
![Page 82: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/82.jpg)
Bruk eksisterende exceptions
![Page 83: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/83.jpg)
IllegalStateExceptionUnsupportedOperationException
IllegalArgumentExceptionNoSuchElementException
NullPointerException
![Page 84: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/84.jpg)
Ikke sluk exceptions
![Page 85: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/85.jpg)
![Page 86: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/86.jpg)
![Page 87: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/87.jpg)
![Page 88: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/88.jpg)
![Page 89: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/89.jpg)
Fallgruver med try-catch-finally
![Page 90: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/90.jpg)
![Page 91: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/91.jpg)
![Page 92: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/92.jpg)
![Page 93: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/93.jpg)
![Page 94: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/94.jpg)
Dokumenter exceptions
![Page 95: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/95.jpg)
![Page 96: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/96.jpg)
![Page 97: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/97.jpg)
Russisk kone
![Page 98: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/98.jpg)
![Page 99: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/99.jpg)
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
![Page 100: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/100.jpg)
Unngå både logging og kasting
![Page 101: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/101.jpg)
![Page 102: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/102.jpg)
Drift trenger unik feilkode for åidentifisere feilen
![Page 103: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/103.jpg)
![Page 104: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/104.jpg)
Utviklere trenger unik instans-ID for å identifisere feilen
![Page 105: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/105.jpg)
![Page 106: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/106.jpg)
Exceptions skal også testes
![Page 107: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/107.jpg)
![Page 108: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/108.jpg)
![Page 109: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/109.jpg)
Bruk stubber for testing av eksterne systemer
![Page 110: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/110.jpg)
<Stub>
Fagsystem A
<interface>
Fagsystem A
Fagsystem A
<interface>
Fagsystem A
![Page 111: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/111.jpg)
Gjør logging enkelt
![Page 112: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/112.jpg)
Gjør logging enkelt
![Page 113: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/113.jpg)
Legg til kontekst der feilen oppstår
![Page 114: Riktig feilhåndtering (og ja, checked exceptions er skadelige)](https://reader030.fdocuments.in/reader030/viewer/2022032619/55bde4d8bb61ebd7558b4784/html5/thumbnails/114.jpg)
BEKK CONSULTING ASSKUR 39, VIPPETANGEN. P.O. BOX 134 SENTRUM, 0102 OSLO, NORWAY. WWW.BEKK.NO
Takk for oppmerksomheten!
trond.arve.wasskog[at]bekk.no