finally with no try/catch?

K

kaeli

Hey all,

At the moment, I have a web application that has an error page that catches
all my errors. This works great. When any of my classes throws an error, the
app forwards on to error.jsp so users can see the error message.
The thing is, classes that throw errors when DB connections, files, and
whatnot are open would get messed up if I didn't close things. So what I did
was to use a try/catch/finally block so that I could close things in the
finally block and just re-threw the exception.

Is there a more elegant way to do this?
I mean, catching errors just to throw them again is rather silly.
But if it's the only way I get a finally, it'll have to do.

The classes in question are beans that are used in a JSP intranet app if it
matters or helps. No struts, I'm afraid, nor Tomcat.

--
--
~kaeli~
She was engaged to a boyfriend with a wooden leg but broke
it off.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
S

Stefan Schulz

kaeli said:
Hey all,

At the moment, I have a web application that has an error page that catches
all my errors. This works great. When any of my classes throws an error, the
app forwards on to error.jsp so users can see the error message.
The thing is, classes that throw errors when DB connections, files, and
whatnot are open would get messed up if I didn't close things. So what I did
was to use a try/catch/finally block so that I could close things in the
finally block and just re-threw the exception.

Is there a more elegant way to do this?
I mean, catching errors just to throw them again is rather silly.
But if it's the only way I get a finally, it'll have to do.

The classes in question are beans that are used in a JSP intranet app if it
matters or helps. No struts, I'm afraid, nor Tomcat.

Why do you catch the Exception in the first place? You _can_ use

try {
// ...
} finally {
// ...
}

just as well. No need to catch anything. In fact, AFAIK this is the main
use for finally.
 
K

kaeli

Why do you catch the Exception in the first place? You _can_ use

try {
// ...
} finally {
// ...
}

just as well. No need to catch anything. In fact, AFAIK this is the main
use for finally.


I thought I HAD to catch it if I was using try.

This was exactly what I was asking if I could do.
Thanks!

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top