Tag Info

New answers tagged

0

Its a reasonably common practice - C programs (and other systems, eg errno) often to store the last error in a location so you can pick the details out if a function returned an error code. There's no reason why you can't do the same. However, if you do this you have to take a few things into consideration. Threads are very important, each error info must ...


2

I have seen this code before in another language (Delphi). It was implemented that way because of an issue where the database (in this case Oracle 7 or 8) wouldn't reliably rollback the first time the rollback method was called. The bug was seemingly random and could not be reliably reproduced - even in production. Rather than spending days tracking down ...


0

Not an anti-pattern per se, but a code pattern that tells you need to refactor. And it's pretty easy, you just have to know a rule of thumb which is writing no more than a try block in the same method. If you know well to write related code together, usually is just copying and pasting each try block with its catch blocks and pasting it inside a new method, ...


0

There nothing mentioned as Anti Pattern in java anywhere. Yes we call few things good practice and bad practice. If a try/catch block is required inside a catch block its required you cant help it. And there is no alternative. As a catch block can't work as try part if exception is thrown. For Example : String str=null; try{ str = method(a); } ...


0

Eliminate the condition, since the compiler things the code could not run at all. Then catch Exception instead of SQLException so it catches NullPointerException in case the connections are not initialized. I usually set the object to null after closing it, because a recommendation I read in a Sybase's EAServer paper and, maybe, it has nothing to do with ...


10

And the tools are right! Apart from the (possible) limitations of the analysis - it may or may not understand that (conn != null) == myConn, observe that rollback throws an SqlException. If it does, then close is never called, which is precisely the definition of a resource leak. Now, it may be the case that with your current DB, drivers and pooling ...


5

Because your release of resources is conditional on the state of a boolean variable and encased in another try block, the static analyzer must be deciding that rollback() and close() are not guaranteed to execute. Check the documentation for the Connection object of the type returned by the getConnection() factory method, and see if the methods rollback() ...


0

Pointless discussion! Checked exceptions are very useful and their handling depends on the kind of product you code is part of: -a library -a desktop application -a server running within some box -an academical exercise Usually a library must not handle checked exceptions, but declare as thrown by public API. The rare case when they could wrapped into ...



Top 50 recent answers are included