Java Exceptions Best Practices
Upcoming SlideShare
Loading in...5
×
 

Java Exceptions Best Practices

on

  • 210 views

Java Exceptions Best Practices

Java Exceptions Best Practices

Statistics

Views

Total Views
210
Views on SlideShare
210
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Java Exceptions Best Practices Java Exceptions Best Practices Presentation Transcript

  • Exceptions in Java
  • An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program.
  • Exception Hierarchy Unchecked CheckedError
  • Three Kinds of Exceptions • Checked - subject to the Catch or Specify Requirement. • Application can recover from it. • Errors - external to the app, app can’t recover from. • Hardware or system malfunction. • Unchecked – not a subject to the Catch or Specify. • Application cannot recover from it. • Usually app bugs.
  • Exception is a part of API
  • Basic example
  • What’s Wrong Here ?
  • Basic example in Java 7
  • What else is in Java 7
  • Custom Exception
  • Exceptions in JUnit
  • Exceptions in JUnit
  • Best Practices • Never swallow the exception in catch block. • Always throw specific exception.
  • Best Practices • Catch specific sub-classes. • Include cause, otherwise stack trace will be lost.
  • Best Practices • Either log the exception or throw it. • Never return or throw from finally block.
  • Thank you!