2017  Kodetalk | Feedback | Privacy Policy | Terms | About

How can I handle the Exception in Java

can any one help me in this :

I am calling a function "add" which is in a class "Example", from a function "More" which is in the Class "example2".If there is any exception produced in function "add" it will generate an error code in Catch block.How can i get that error code from the Function add to function More only if the exception had occured.

If the error code generated by method add on exception is unique (meaning that no normal output from add will ever match that error code), you can simply do this (assuming that error code returned on exception is -1):

if(Example.add() == -1) {
    //Do stuff when exception occurred

Answer is