my dog learned polymorphism
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Application exception" Watch "Application exception" New topic

Application exception

Tmmet Johnson
Ranch Hand

Joined: Nov 03, 2004
Posts: 56
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: 15082

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 8 API documentation
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
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.

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
I agree. Here's the link:
subject: Application exception
It's not a secret anymore!