aspose file tools
The moose likes Beginning Java and the fly likes weird exception Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "weird exception" Watch "weird exception" New topic
Author

weird exception

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 758

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: 490

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: 24061
    
  13

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: 758
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: weird exception
 
Similar Threads
Not catching my own exception in my code
serialization
Exception Doubt
try-catch-finally
Can somebody please explain me the output