try{} catch{} finally{} statement

If something doesn't fit in any other forum then post it here.
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
VlLight
L2j Veteran
L2j Veteran
Posts: 577
Joined: Fri Dec 14, 2007 11:58 am
Location: Russia

try{} catch{} finally{} statement

Post 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?
User avatar
LasTravel
Posts: 888
Joined: Tue Jan 05, 2010 12:08 am
Location: Spain

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

Post by LasTravel »

User avatar
VlLight
L2j Veteran
L2j Veteran
Posts: 577
Joined: Fri Dec 14, 2007 11:58 am
Location: Russia

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

Post by VlLight »

Thanks :) But I interested, if i return from try{} block
Offtopic is wrong section? Sorry :)
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

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

Post by jurchiks »

you shouldn't do that, it will most probably result in an unclosed connection.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
User avatar
LasTravel
Posts: 888
Joined: Tue Jan 05, 2010 12:08 am
Location: Spain

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

Post 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
User avatar
VlLight
L2j Veteran
L2j Veteran
Posts: 577
Joined: Fri Dec 14, 2007 11:58 am
Location: Russia

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

Post by VlLight »

Are you quite sure?
User avatar
VlLight
L2j Veteran
L2j Veteran
Posts: 577
Joined: Fri Dec 14, 2007 11:58 am
Location: Russia

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

Post by VlLight »

LasTravel, thanks, nice trick. I'll try
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

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

Post by jurchiks »

there's nothing to try, everybody knows that return is the end, it won't go past it.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
User avatar
VlLight
L2j Veteran
L2j Veteran
Posts: 577
Joined: Fri Dec 14, 2007 11:58 am
Location: Russia

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

Post 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
_DS_
L2j Veteran
L2j Veteran
Posts: 3437
Joined: Wed Apr 30, 2008 8:53 am
Location: Russia

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

Post by _DS_ »

No such unreachable code in LoginController.
Commiter of the shit
public static final int PI = 3.1415926535897932384626433832795;
User avatar
VlLight
L2j Veteran
L2j Veteran
Posts: 577
Joined: Fri Dec 14, 2007 11:58 am
Location: Russia

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

Post by VlLight »

loginValid() try{} block.
User avatar
JIV
L2j Veteran
L2j Veteran
Posts: 1882
Joined: Sun Jan 06, 2008 8:17 pm
Location: Slovakia
Contact:

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

Post by JIV »

nothing wrong with that method.
Post Reply