This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes weird exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "weird exception" Watch "weird exception" New topic
Author

weird exception

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798

I have code like below, if update has a runtime exception, it will not go to Exception block and will continue the block left. Output will be

11
22
44

That is weird. What I expect is 11 33.

Please help. Thanks.

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

I don't see anywhere in your code where you are throwing an exception. Is line 4 supposed to throw an exception??
You also shouldn't being throwing exceptions inside your catch block.

Basic try/catch:

-Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Edward: I understand what you're saying. You're correct that 11 22 44 is what you will see when there is no exception, and you'll see 11 33 when there's not. If you're seeing 11 22 44, then no exception is being thrown here. Perhaps StaleObjectStateException is being thrown internally, inside update(), which is printing a message and returning normally?


[Jess in Action][AskingGoodQuestions]
Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
Ernest Friedman-Hill wrote: You're correct that 11 22 44 is what you will see when there is no exception, and you'll see 11 33 when there's not.


Sorry, give you confusion. when Line 4 throw a StaleObjectStateException´╝î it will give me 11 22 44. It will be same as when there is NO exception. But what I want is when there is an exception, output will be 11 33.


Ernest Friedman-Hill wrote: Perhaps StaleObjectStateException is being thrown internally, inside update(), which is printing a message and returning normally?

What do you mean "thrown internally" ?

Spring framework provides a wrapper, org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException for this runtime exception. Is this wrapper class related to this weird thing ?

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: weird exception