Page 1 of 1

try{} catch{} finally{} statement

Posted: Fri Dec 17, 2010 10:56 pm
by VlLight
Please explain to me.. if I have next statement:

private void doSomeThing()
{
try
{
Connection con = L2DatabaseFactory.getInstance().getConnection();
return;
}
catch {}
finally {L2DatabaseFactory.close(con);}
}

will connection close?

Re: try{} catch{} finally{} statement

Posted: Fri Dec 17, 2010 10:59 pm
by LasTravel

Re: try{} catch{} finally{} statement

Posted: Fri Dec 17, 2010 11:02 pm
by VlLight
Thanks :) But I interested, if i return from try{} block
Offtopic is wrong section? Sorry :)

Re: try{} catch{} finally{} statement

Posted: Fri Dec 17, 2010 11:09 pm
by jurchiks
you shouldn't do that, it will most probably result in an unclosed connection.

Re: try{} catch{} finally{} statement

Posted: Fri Dec 17, 2010 11:14 pm
by LasTravel
You can try something like this:

Code: Select all

private void doSomeThing(){    try    {        Connection con = L2DatabaseFactory.getInstance().getConnection();        return;        _log.warning("Return don't work here!")    }    catch {}    finally     {        L2DatabaseFactory.close(con);        _log.warning("DB connection was closed!")    }}
Just need check the console XD

Re: try{} catch{} finally{} statement

Posted: Fri Dec 17, 2010 11:18 pm
by VlLight
Are you quite sure?

Re: try{} catch{} finally{} statement

Posted: Fri Dec 17, 2010 11:20 pm
by VlLight
LasTravel, thanks, nice trick. I'll try

Re: try{} catch{} finally{} statement

Posted: Fri Dec 17, 2010 11:33 pm
by jurchiks
there's nothing to try, everybody knows that return is the end, it won't go past it.

Re: try{} catch{} finally{} statement

Posted: Fri Dec 17, 2010 11:41 pm
by VlLight
There's much of that code in LoginController... :roll: I hate code in holiday, but chek it in weekdays :)
Big thanks to all

Re: try{} catch{} finally{} statement

Posted: Sat Dec 18, 2010 8:01 am
by _DS_
No such unreachable code in LoginController.

Re: try{} catch{} finally{} statement

Posted: Sat Dec 18, 2010 11:16 am
by VlLight
loginValid() try{} block.

Re: try{} catch{} finally{} statement

Posted: Sat Dec 18, 2010 1:35 pm
by JIV
nothing wrong with that method.