aspose file tools*
The moose likes Java in General and the fly likes question on exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "question on exception handling" Watch "question on exception handling" New topic
Author

question on exception handling

Vivek S. kumar
Greenhorn

Joined: Dec 19, 2006
Posts: 25
hie

i have say Class1 calling a method of Class2 with signature void sayHello(String name);

i deploy the stuff to a web server where it runs fine as expected.

Now if i replace the Class2.class from server with another Class2.class where signature is void sayHello()

and now if i run the app it will break with method not found stack trace.

Can i handle such problem programmatically?


"Make Your Own Rules and Rock The World"
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

While you could catch Throwable, how would you handle such a thing? Someone changing the code out from under you isn't something that is recoverable.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

Sounds like you are trying to solve a problem at run-time caused by a broken build and deployment strategy. Fix the strategy.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vivek S. kumar
Greenhorn

Joined: Dec 19, 2006
Posts: 25
Jeanne Boyarsky wrote:While you could catch Throwable, how would you handle such a thing? Someone changing the code out from under you isn't something that is recoverable.


well fine i cannot recover but can i at least catch such situation?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

But what is the point of catching it if you can't do anything about it?

Avoid the entire situation by fixing your build and deployment strategy.
Vivek S. kumar
Greenhorn

Joined: Dec 19, 2006
Posts: 25
Bear Bibeault wrote:But what is the point of catching it if you can't do anything about it?

Avoid the entire situation by fixing your build and deployment strategy.


Well doesn't that make sense to show user a bit meaningful error of what might be wrong rather throwing a full page stack trace error? So back to original question can i catch such error?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Yes, you can. Have you tried it? In the code, it should be just like catching any other exception.

I strongly recommend that in addition to presenting the user with a nice friendly looking message, you make sure the complete details of the exception (including stack trace) are logged in a file somewhere. Because there's usually a lot of useful information in those things, and people who try to protect end users from seeing them very often manage to lose that useful information in the process. Don't be one of those people.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question on exception handling