filmov
tv
Exception handling Interview Questions and Answers in Java | Code Decode | Live Demo | Part 2

Показать описание
Experienced and Freshers both candidate can refer this video of Code Decode Exception handling Interview Questions and Answers
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
Course Description Video :
This video covers exception handling frequently asked interviews and answers with Live code demos . It covers Chained exceptions, exception propagation such concepts.
Lets understand this with an example. Where the normal flow of your java application goes like this. You send a http request for a resource to controller.
Controller handles it and send to Service where business logic is written which in turn gives inputs to DAO layer If database interaction is needed. Then finally data is Added or fetched to or from data base back to Same flow from DB to DAO to Service/ business layer to controller which sends response to UI and u get the data form the DB or update the data in DB.
Now Consider a situation where Database exception occurs and u need to tell this to user. You can see multiple layer in between. How to preserve the original exception when it propagates across multiple logical layers in a program?
Answer is through Exception Chaining.
Here Database throws SQLException. Which is caught by DAO class.
DAO class throws DAOException which is caught by Catch block in Service class.
Service class throws the catched DAO exception as ServiceException which in turn is caught by controller .
Controller will now handle it appropriately and send the user friendly message to UI to be shown.
The printed exception stack trace reveals an exception propagates from the SQL / DB layer up to the Controller layer.
This is called exception propagation which helps in debugging process.
Chained Exceptions allows to relate one exception with another exception, i.e one exception describes cause of another exception.
Methods Of Throwable class Which support chained exceptions in java :
getCause() method :- This method returns actual cause of an exception
initCause(Throwable cause) method :- This method sets the cause for the calling exception.
The initCause() method of Throwable class is used to initialize the cause of the this Throwable with the specified cause passed as a parameter to initCause(). Actually, the cause is the throwable that caused this throwable Object to get thrown when an exception occurs. This method can be called only once. Generally, This method is called from within the constructor, or immediately after creating the throwable.
Chained exception helps during exception handling. you get the real cause of exception
Subscriber and Follow Code Decode
#codedecode #exceptionhandling #javainterviewquestions
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
Course Description Video :
This video covers exception handling frequently asked interviews and answers with Live code demos . It covers Chained exceptions, exception propagation such concepts.
Lets understand this with an example. Where the normal flow of your java application goes like this. You send a http request for a resource to controller.
Controller handles it and send to Service where business logic is written which in turn gives inputs to DAO layer If database interaction is needed. Then finally data is Added or fetched to or from data base back to Same flow from DB to DAO to Service/ business layer to controller which sends response to UI and u get the data form the DB or update the data in DB.
Now Consider a situation where Database exception occurs and u need to tell this to user. You can see multiple layer in between. How to preserve the original exception when it propagates across multiple logical layers in a program?
Answer is through Exception Chaining.
Here Database throws SQLException. Which is caught by DAO class.
DAO class throws DAOException which is caught by Catch block in Service class.
Service class throws the catched DAO exception as ServiceException which in turn is caught by controller .
Controller will now handle it appropriately and send the user friendly message to UI to be shown.
The printed exception stack trace reveals an exception propagates from the SQL / DB layer up to the Controller layer.
This is called exception propagation which helps in debugging process.
Chained Exceptions allows to relate one exception with another exception, i.e one exception describes cause of another exception.
Methods Of Throwable class Which support chained exceptions in java :
getCause() method :- This method returns actual cause of an exception
initCause(Throwable cause) method :- This method sets the cause for the calling exception.
The initCause() method of Throwable class is used to initialize the cause of the this Throwable with the specified cause passed as a parameter to initCause(). Actually, the cause is the throwable that caused this throwable Object to get thrown when an exception occurs. This method can be called only once. Generally, This method is called from within the constructor, or immediately after creating the throwable.
Chained exception helps during exception handling. you get the real cause of exception
Subscriber and Follow Code Decode
#codedecode #exceptionhandling #javainterviewquestions
Комментарии