SlideShare a Scribd company logo
Best Practices
Exception Handling
Abid Hossain Khan
Agenda
ļ‚— Advantages
ļ‚— Exception Hierarchy
ļ‚— Best Practices
Advantages
ļ‚— Represent a meaningful message to user
ļ‚— Log unhandled exception once and only once
ļ‚— Correlate exceptions with unique request id (session) in
log file for high precision debugging
ļ‚— Implement powerful but extensible exception handling
strategy for each tiers
Exception Hierarchy
Best Practice : 1
ļ‚— Never swallow exception in catch block
Best Practice : 2
ļ‚— Declare the specific checked exceptions that your
method can throw
Best Practice : 3
ļ‚— Do not catch the Exception class rather catch specific
sub classes
Best Practice : 4
• Never catch Throwable class
Best Practice : 5
ļ‚— Always correctly wrap the exceptions in custom
exceptions so that stack trace is not lost
Best Practice : 6
ļ‚— Either log the exception or throw it but never do the
both
Best Practice : 7
ļ‚— Never throw any exception from finally block
Best Practice : 8
ļ‚— Always catch only those exceptions that you can
actually handle
Best Practice : 9
ļ‚— Don’t use printStackTrace() statement or similar
methods
Best Practice : 10
ļ‚— Use finally blocks instead of catch blocks if you are not
going to handle exception
Best Practice : 11
ļ‚— Throw early catch late
Best Practice : 12
ļ‚— Always clean up after handling the exception
Best Practice : 13
• Throw only relevant exception from a method
Best Practice : 14
ļ‚— Never use exceptions for flow control in your program
Best Practice : 15
ļ‚— Always include all information about an exception in
single log message
Best Practice : 16
ļ‚— Use template methods for repeated try-catch
Best Practice : 17
ļ‚— Document all exceptions in your application in javadoc
Coding best practices_exception handling
Coding best practices_exception handling

More Related Content

Viewers also liked (11)

PPT
9 cm604.42
myrajendra
Ā 
PPT
12 exception handling
Arriz San Juan
Ā 
PDF
Java Pitfalls and Good-to-Knows
Miquel Martin
Ā 
PPTX
Anti patterns part 2
Return on Intelligence
Ā 
ODP
Exception handling in java
priyankazope
Ā 
PDF
null Bachaav Session | Secure Coding in Java
n|u - The Open Security Community
Ā 
PPTX
OCA Java SE 8 Exam Chapter 6 Exceptions
İbrahim Kürce
Ā 
PPTX
Applet programming in java
Vidya Bharti
Ā 
PDF
Exception handling and logging best practices
Angelin R
Ā 
PDF
Java & J2EE Coding Conventions
Vijaya Raghava Vuligundam
Ā 
9 cm604.42
myrajendra
Ā 
12 exception handling
Arriz San Juan
Ā 
Java Pitfalls and Good-to-Knows
Miquel Martin
Ā 
Anti patterns part 2
Return on Intelligence
Ā 
Exception handling in java
priyankazope
Ā 
null Bachaav Session | Secure Coding in Java
n|u - The Open Security Community
Ā 
OCA Java SE 8 Exam Chapter 6 Exceptions
İbrahim Kürce
Ā 
Applet programming in java
Vidya Bharti
Ā 
Exception handling and logging best practices
Angelin R
Ā 
Java & J2EE Coding Conventions
Vijaya Raghava Vuligundam
Ā 

Similar to Coding best practices_exception handling (20)

PPTX
Exception-Handling-in-Java-A-Comprehensive-Guide (1).pptx
singharyan4506
Ā 
PDF
Exception handling & logging in Java - Best Practices (Updated)
Angelin R
Ā 
PPTX
Java Exception Handling and examples about it
2022002857mbit
Ā 
PPT
Exception handling in java
Pratik Soares
Ā 
ODP
Effective exceptions
parag
Ā 
PDF
Exception Handling_ Mastering the Art of Dealing with Errors and Exceptions.pdf
RamirezCarl
Ā 
PDF
Exception Handling.pdf
lsdfjldskjf
Ā 
PDF
Best Practices in Exception Handling
Lemi Orhan Ergin
Ā 
PPTX
12. Java Exceptions and error handling
Intro C# Book
Ā 
PPTX
Training material exceptions v1
Shinu Suresh
Ā 
PPTX
IEEE ACM Studying the Relationship between Exception Handling Practices and P...
Gui Padua
Ā 
PPT
Java: Exception
Tareq Hasan
Ā 
PDF
Exception handling
Garuda Trainings
Ā 
PDF
Exception handling
Garuda Trainings
Ā 
PDF
Class notes(week 8) on exception handling
Kuntal Bhowmick
Ā 
PPTX
exceptionhandlinginjava-140224181412-phpapp02.pptx
ARUNPRANESHS
Ā 
PPTX
130410107010 exception handling
Hemant Chetwani
Ā 
PPT
Dealing exception.43
myrajendra
Ā 
PPTX
Introduction to java exceptions
Sujit Kumar
Ā 
Exception-Handling-in-Java-A-Comprehensive-Guide (1).pptx
singharyan4506
Ā 
Exception handling & logging in Java - Best Practices (Updated)
Angelin R
Ā 
Java Exception Handling and examples about it
2022002857mbit
Ā 
Exception handling in java
Pratik Soares
Ā 
Effective exceptions
parag
Ā 
Exception Handling_ Mastering the Art of Dealing with Errors and Exceptions.pdf
RamirezCarl
Ā 
Exception Handling.pdf
lsdfjldskjf
Ā 
Best Practices in Exception Handling
Lemi Orhan Ergin
Ā 
12. Java Exceptions and error handling
Intro C# Book
Ā 
Training material exceptions v1
Shinu Suresh
Ā 
IEEE ACM Studying the Relationship between Exception Handling Practices and P...
Gui Padua
Ā 
Java: Exception
Tareq Hasan
Ā 
Exception handling
Garuda Trainings
Ā 
Exception handling
Garuda Trainings
Ā 
Class notes(week 8) on exception handling
Kuntal Bhowmick
Ā 
exceptionhandlinginjava-140224181412-phpapp02.pptx
ARUNPRANESHS
Ā 
130410107010 exception handling
Hemant Chetwani
Ā 
Dealing exception.43
myrajendra
Ā 
Introduction to java exceptions
Sujit Kumar
Ā 
Ad

Recently uploaded (20)

PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
Ā 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
Ā 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
Ā 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
Ā 
PPTX
How Cloud Computing is Reinventing Financial Services
Isla Pandora
Ā 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
Ā 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
Ā 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
Ā 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
Ā 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
Ā 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
Ā 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
Ā 
PDF
ģœ ė‹ˆķ‹°ģ—ģ„œ Burst Compiler+ThreadedJobs+SIMD ģ ģš©ģ‚¬ė”€
Seongdae Kim
Ā 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
Ā 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
Ā 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
Ā 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
Ā 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
Ā 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
Ā 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
Ā 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
Ā 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
Ā 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
Ā 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
Ā 
How Cloud Computing is Reinventing Financial Services
Isla Pandora
Ā 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
Ā 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
Ā 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
Ā 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
Ā 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
Ā 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
Ā 
Import Data Form Excel to Tally Services
Tally xperts
Ā 
ģœ ė‹ˆķ‹°ģ—ģ„œ Burst Compiler+ThreadedJobs+SIMD ģ ģš©ģ‚¬ė”€
Seongdae Kim
Ā 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
Ā 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
Ā 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
Ā 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
Ā 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
Ā 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
Ā 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
Ā 
Ad

Coding best practices_exception handling

Editor's Notes

  • #12: What is actor model Actor model is a universal primitive of concurrent computation in computer science. Ā  How actor behaves Once an actor receives a message it can Ā  It can make local decision. It can create more actors Send more messages Determine how to respond to the next message received
  • #13: In java object and thread in not unified. But in actor model these two has been unified together.
  • #14: Encapsulation : There is no shared state between actors Actor is access by passing message. (Message is immutable i.e. it is only pass by value) Fairness: The notation of fairness states that every actor makes progress if some computation it has to do and every message is eventually delivered to destination actor unless destination actor is not permanently disabled. Location Transparency Actual location of actor does not effect its name (processing). Actor communicated by exchanging message with other actors which can be on same CPU or on another node in cluster. It provides an abstraction to the developer to work with out worrying about physical location of actors. Mobility Mobility is defined as the ability of computation to migrate across different nodes. Mobility is important for load-balancing, fault-tolerance and reconfiguration. It is important for developing scalable applications.