• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot access all values in caught exception  RSS feed

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an exception that I am populating when an error occurs in the code below:



After this exception is thrown I try to catch the exception in the following code:



However, I want to include the "fieldName" in the ValidationException above but I cannot seem to get to it in the ApplicationException being caught. I see the "error" in the e.getMessage but I cannot access the fieldname. I see it in debugger when I am stepping through my code in Eclipse but I cannot get to it.

If anyone can please tell me what I'm doing wrong or give me some direction on how to fix my issue it would be appreciated.

Thanks.

 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume ValidationException is a subclass of ApplicationException?

If you want to access methods belonging to ValidationException, you're going to need a ValidationException reference. So you can either catch that in the first place, or you can cast e to ValidationException (after checking e instanceof ValidationException, of course).
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I tried the CAST option that you stated however I'm still NOT seeing the "fieldName" value or option to access the value of fieldName from the CAST. Perhaps I'm doing something wrong here or I totally misunderstood what you meant. Here is the code I tried:



Again any help would be appreciated. Thanks.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not really clear (to me, anyway) how the fieldName relates to the ValidationException. How are you "including" it? If ValidationException is a custom class it might be helpful to post the definition.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Matthew. I am working with Stripes and I was not accessing the correct ValidationException and therefore the reason I could not see the methods. I will try and again and post again if I run into a problem.

Sorry for the confusion. Regards.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!