PDA

Click to See Complete Forum and Search --> : why do JDBC lines of code require a try/catch block be provided. ?


vb_student
Nov 18th, 2006, 06:34 PM
Hello

why do JDBC lines of code require a try/catch block be provided. ?

System_Error
Nov 18th, 2006, 07:53 PM
Hello

why do JDBC lines of code require a try/catch block be provided. ?

a number of exceptions could be thrown. You may provide a bad password, bad db name, or the connection may fail due to some obscure reason. *Just because you want to establish a connection with a database doesn't mean it's going to happen.

Buoy
Nov 18th, 2006, 08:17 PM
It's been a while since I've done Java, but if I remember correctly, exceptions can be defined as checked or non-checked. A checked exception must either handle the exception, or throw it.

So whoever wrote the JDBC methods thought it was a good idea to have those methods use checked exceptions.

There's a lot of discussion on whether checked exceptions are a good idea or not. I'm not offering an opinion, but that's the way it is in Java.