• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question on exception handling

 
Vivek S. kumar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34870
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you are trying to solve a problem at run-time caused by a broken build and deployment strategy. Fix the strategy.
 
Vivek S. kumar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic