From: Elliotte H. <el...@me...> - 2005-08-16 12:02:50
|
Torsten Curdt wrote: > Hi there, > > I am wondering how you guys think empty try/catch > should be handled. > > Let's assume I have > > try { > Thread.sleep(1000); > } catch(InterruptedException e) { > ; > } That block is not empty. It contains an empty statement. Possibly the compiler will optimize this away. I'm not sure. You definitely should test this catch block if you can. That is, you should write a test case in which the sleeping thread is interrupted and then verify that everything still behaves as it should. If you really think it's impossible for the thread to be interrupted, then you should rewrite the catch block along these lines: catch(InterruptedException e) { throw new RuntimeException(e, "Something impossible happened") ; } -- Elliotte Rusty Harold el...@me... XML in a Nutshell 3rd Edition Just Published! http://www.cafeconleche.org/books/xian3/ http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim |