try{} catch{} finally{} statement
Forum rules
READ NOW: L2j Forums Rules of Conduct
READ NOW: L2j Forums Rules of Conduct
- VlLight
- L2j Veteran
- Posts: 577
- Joined: Fri Dec 14, 2007 11:58 am
- Location: Russia
try{} catch{} finally{} statement
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?
private void doSomeThing()
{
try
{
Connection con = L2DatabaseFactory.getInstance().getConnection();
return;
}
catch {}
finally {L2DatabaseFactory.close(con);}
}
will connection close?
- LasTravel
- Posts: 888
- Joined: Tue Jan 05, 2010 12:08 am
- Location: Spain
- VlLight
- L2j Veteran
- Posts: 577
- Joined: Fri Dec 14, 2007 11:58 am
- Location: Russia
Re: try{} catch{} finally{} statement
Thanks
But I interested, if i return from try{} block
Offtopic is wrong section? Sorry

Offtopic is wrong section? Sorry

- jurchiks
- Posts: 6769
- Joined: Sat Sep 19, 2009 4:16 pm
- Location: Eastern Europe
Re: try{} catch{} finally{} statement
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.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
- LasTravel
- Posts: 888
- Joined: Tue Jan 05, 2010 12:08 am
- Location: Spain
Re: try{} catch{} finally{} statement
You can try something like this:
Just need check the console XD
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!") }}
- VlLight
- L2j Veteran
- Posts: 577
- Joined: Fri Dec 14, 2007 11:58 am
- Location: Russia
Re: try{} catch{} finally{} statement
Are you quite sure?
- VlLight
- L2j Veteran
- Posts: 577
- Joined: Fri Dec 14, 2007 11:58 am
- Location: Russia
Re: try{} catch{} finally{} statement
LasTravel, thanks, nice trick. I'll try
- jurchiks
- Posts: 6769
- Joined: Sat Sep 19, 2009 4:16 pm
- Location: Eastern Europe
Re: try{} catch{} finally{} statement
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.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
- VlLight
- L2j Veteran
- Posts: 577
- Joined: Fri Dec 14, 2007 11:58 am
- Location: Russia
Re: try{} catch{} finally{} statement
There's much of that code in LoginController...
I hate code in holiday, but chek it in weekdays 
Big thanks to all


Big thanks to all
-
- L2j Veteran
- Posts: 3437
- Joined: Wed Apr 30, 2008 8:53 am
- Location: Russia
Re: try{} catch{} finally{} statement
No such unreachable code in LoginController.
Commiter of the shit
public static final int PI = 3.1415926535897932384626433832795;
public static final int PI = 3.1415926535897932384626433832795;
- VlLight
- L2j Veteran
- Posts: 577
- Joined: Fri Dec 14, 2007 11:58 am
- Location: Russia
Re: try{} catch{} finally{} statement
loginValid() try{} block.
- JIV
- L2j Veteran
- Posts: 1882
- Joined: Sun Jan 06, 2008 8:17 pm
- Location: Slovakia
- Contact:
Re: try{} catch{} finally{} statement
nothing wrong with that method.