• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Catch me if You Can  RSS feed

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My error class is defined like this:
///---------------------------------------------------------------
//------------------------------------------------------------------

In other class I try and catch as follows, and in the catch block, I want to throw new. How do I "throw new"?


I want to get "why" information and also "trace" information.
How do I extract and pass that info. to initSomething() caller?
 
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand what you're asking, the solution is to pass the original exception into the new exception's constructor. Java's Exception class has had this ability since JDK 1.4 with the constructor public Exception(String message, Throwable cause). The printStackTrace() method is also aware of "causes" now and will include them in the stack trace. The only problem is whether your Corba exception base class provides such a constructor. If not, you'll have to get a bit tricky with overrides.

Let me know if this helps.
 
Sheriff
Posts: 23710
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that exception doesn't have a constructor which accepts another exception as a cause. But I don't think that any trickery would be required, because there's the "initCause(Throwable)" method which was also added in 1.4. So when you create the exception, you then call that method to set up the cause with the real exception which caused you to throw that one.
 
Tien Shan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Greg, Paul.

Greg, I tried
throw new NotExist(e.getMessage(), e.getCause());
but it gave me error, constructor (string, throwable) not defined

Paul,
How would I put that into code?
The other way of saying this is that you will have to come down to my level.



 
Paul Clapham
Sheriff
Posts: 23710
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't tell you because I can't understand what you are trying to do. You have code in a catch block which catches this "NotExist" exception, and then what? You want to throw another NotExist exception? Why can't you just throw the one you already have? (And if you can, then why did you catch it in the first place?)

Or if you want to throw a new exception, what's going to go into that description?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!