*
The moose likes Java in General and the fly likes Application exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Application exception" Watch "Application exception" New topic
Author

Application exception

Tmmet Johnson
Ranch Hand

Joined: Nov 03, 2004
Posts: 56
Hi,
I throw an application exception as below in my catch blocks.
Does this catch block will miss the stacktrace exception when finally caught in the caller method?
Could anyone please let me know?Thanks in advance,

[ Edited to include code tags - Paul Sturrock ]
[ November 01, 2006: Message edited by: Paul Sturrock ]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

You are throwing a new exception in the catch block. The caller that catches the ValidationFailedException will ofcourse only be able to see the stacktrace of the ValidationFailedException, and not the stacktrace of the original DataValidationException.

You could have found out this for yourself by writing a small test program.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
You can add the original exception to your new exception, either by adding a constructor that accepts a Throwable as an argument and calls the appropriate super class constructor or by calling the initCause() method.
Then the code that catches your exception can retrieve the original exception using the getCause() method.


Joanne
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Application exception
 
Similar Threads
Query about Composite keys - Hibernate
Hibernate or browser caching DB results?
Trying to understand when to use 'finally' clause
Why should we use a finally block?
need decrypt method