• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sql Exception

 
Natesan Prabhakaran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
Is sqlException is RunTime Exception or CompileTime Exception., I know it is CompileTime Exception, then how it is working while compiletime., its confusing me. Thanks.

Regards
Prabhakaran.N
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Can you make the situation more clear by asking the specific question.
 
Natesan Prabhakaran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection is establised during the runtime and find correct database, table and query are executed in runtime, then how it is compiletime exception., i dont know how..? please explain.

thanks.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exceptions are ALWAYS thrown at runtime.

What you call CompileTimeException is actually called a checked exception. It differs from RuntimeException only in that you HAVE to catch or rethrow it.
Mostly, RuntimeExceptions are caused by mistakes by a programmer; often he just doesn't check if some assertion holds.
- IllegalArgumentException indicates a value has not been checked properly first
- NullPointerException indicates a value hasn't been checked against being null
- ArithmeticException indicates the programmer wanted to perform some arithmetic which isn't allowed (integer division by 0)

Checked exceptions on the other hand, are more often caused by external factors. A database can fail (SQLException), a hard drive or filesystem can fail (IOException), a network can fail (SocketException), etc. The programmer cannot check these things most of the times, and therefore is forced to handle the error.

Please note that a programmer can also throw checked exceptions to make sure other programmers are always aware of the exception, and don't just forget about them (which happens with NullPointerExceptions mostly).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic