270 likes | 753 Views
This presentation on "Exception Handling in Java" will help you to learn the Java Exceptions Hierarchy and also helps you to learn how to handle various exceptions in java with practical examples.<br><br><br>About Simplilearn Java certification training course:<br>If youu2019re looking to master web application development for virtually any computing platform, this Java Certification Training course is for you. This all-in-one Java training will give you a firm foundation in Java, the most commonly used programming language in software development.<br><br>This advanced Java Certification Training course is designed to guide you through the concepts of Java from introductory techniques to advanced programming skills. The course will provide you with the knowledge of Core Java 8, operators, arrays, loops, methods, and constructors while giving you hands-on experience in JDBC and JUnit framework.<br><br>Java Certification Course Key Features:<br>1. 70 hours of blended training<br>2. Hands-on coding and implementation of two web-based projects<br>3. Includes Hibernate and Spring frameworks<br>4. 35 coding-related exercises on Core Java 8<br>5. Lifetime access to self-paced learning<br>6. Flexibility to choose classes<br><br>Eligibility:<br>Simplilearnu2019s Java Certification Training course is ideal for software developers, web designers, programming enthusiasts, engineering graduates, and students or professionals who wish to become Java developers.<br><br>Pre-requisites:<br>Prior knowledge of Core Java is a prerequisite to taking this advanced Java Certification training course. Our Core Java online self-paced course is available for free to become familiar with the basics of Java programming.<br><br>ud83dudc49Learn more at: https://bit.ly/3b6SCvp
E N D
Agenda What is an Exception? What is an Error? Error v/s Exception Exception Hierarchy Checked v/s Unchecked Common Exceptions Exception Handling Best Practices
01 What is an Exception?
What is an Exception? An exception is an unexpected scenario that pops up during run time and disrupts the normal execution flow a program
02 What is an Error?
What is an Error? An error is a unexpected even that arises due to logical or syntactical mistake and is capable to bring down the complete program.
03 Error V/S Exception
Error V/S Exception Exception Error Checked and Unchecked type Unchecked Type Recoverable Irrecoverable Class: java.lang.error Class: java.lang.Exception Run-time and Compile-time Occurs only at Run-time Ex: divideByZero Exception Ex: IO-Error
04 Exception Hierarchy
Exception Hierarchy Throwable Error Exception JVM Error IO-Exception Memory SQL-Exception Framework ClassNotFound Run-Time Arithmetic NumberFormat
05 Checked V/S Unchecked
Checked V/S Unchecked Exception An exception that pops up during compile time is called checked exception. It is not serious and ignorable An exception that pops up at run time is called unchecked exception. It is serious and caused by logical errors
06 Common Exceptions
Common Exceptions ArrayIndexOutOfBound In case, if you try to store a value in the array location which has an address exceeding the array’s maximum location value, this exception is thrown
Common Exceptions NullPointer In case, if you try to perform an operation on a null value, then this exception is thrown
Common Exceptions NumberFormat In case, if you try to store a value with wrong formatting, then this exception is thrown
Common Exceptions Arithmetic In case, if you try to divide a number by zero , this exception is thrown
07 Exception Keywords
Exception Keywords in Java Method Description Keyword The try key word is used to specify the exception block try The catch keyword is used to specify the solution catch finally The finally keyword has mandatorily executable code The throw keyword throws an exception throw The throws keyword is used to declare exception throws
08 Best Practices
Best Practices Use Exceptions conservatively Exceptions have proven that they can be costly if used recklessly. Its better we use Boolean values to indicate successful implementation of smaller operations
Best Practices Customized Exceptions It’s a very good practice of customizing your exceptions in the design time rather than planning them on the go
Best Practices Exceptions Logging Keeping track of the exceptions comes handy as the user understands why a particular exception popped up
Best Practices Early Throw and Fail An exception should be thrown as early as possible and should be resolved in the same pace.
Best Practices Closing Resources Since Exceptions halt the complete program, we must make sure the system resources are shut so as to save the resources