You need to sign in to do that
Don't have an account?

inserting a record before a null pointer exception is fired
Hello,
i have a use case where i wamt to isert record in to custom log before a null pointer exception is fired.
I am reproducting the null exception and adding log.
but i see that the log is not inserted before the null pointer exception is fired
what can be the issue please
i have a use case where i wamt to isert record in to custom log before a null pointer exception is fired.
I am reproducting the null exception and adding log.
but i see that the log is not inserted before the null pointer exception is fired
what can be the issue please
What you can do is to catch the NPE and insert your Log in the catch block. After that you can rethrow your exception.
Code example:
try{
// code that will produce the Null Pointer Exception
} catch (NullPointerException npe){
//Insert your Log here
//rethrow the NPE
}
Note that letting null pointer exceptions live in your environment is really, really bad thing. Try to reduce exceptions to 0, as they are considered as "Exceptional behaviour", which means they should not be a part of the normal/regular execution of your code.
All Answers
This might help you.
What you can do is to catch the NPE and insert your Log in the catch block. After that you can rethrow your exception.
Code example:
try{
// code that will produce the Null Pointer Exception
} catch (NullPointerException npe){
//Insert your Log here
//rethrow the NPE
}
Note that letting null pointer exceptions live in your environment is really, really bad thing. Try to reduce exceptions to 0, as they are considered as "Exceptional behaviour", which means they should not be a part of the normal/regular execution of your code.
i am following your method, but the inser is not working.
I am able to do it on when i dot rethow execption bu t it is not my usecase