method return

Hi,

i have a method with try catch.


Do i need to have separate return within try block and also one other return after catch block( i see null is being reurned there which is not clear why to me).

Please advise
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
please post your code.
ozoCommented:
Not necessarily.  Why do you ask?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
my question is can catch block itself return null as return as soon as it comes out of if block and comes inside catch block
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

gudii9Author Commented:
class Exc2 {
public static void main(String args[]) {
int d, a;
try { // monitor a block of code.
d = 0;
a = 42 / d;
System.out.println("This will not be printed.");
} catch (ArithmeticException e) { // catch divide-by-zero
//error
System.out.println("Division by zero.");
return null;//can i do this??? any way flow did not go through 'if' loop then it can only go to 'else' loop right? is there is scenario flow does not go through 'if' or 'try'
}

return null;//is this is needed???
System.out.println("After catch statement.");
}
}
gudii9Author Commented:
my question is more with example method which expects return not void.

i am trying to find example to explain more clearly
gudii9Author Commented:
public String execute() throws Exception{
    try{
        //Do blah
        return "success"; //Assuming everything goes well, return success.
    }catch (Exception e){
        e.printStackTrace();
    }
    return "error";
}

like above
gudii9Author Commented:
gudii9Author Commented:
please advise
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.