ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Try Catch in ESQL

Post new topic  Reply to topic
 Try Catch in ESQL « View previous topic :: View next topic » 
Author Message
gaurav.udgir
PostPosted: Wed Aug 12, 2009 6:14 am    Post subject: Try Catch in ESQL Reply with quote

Apprentice

Joined: 18 May 2009
Posts: 32

Hi All.

I want to throw a user generated exception instead of MB generated exception. I am trying to get something similar to try catch(as in java) in ESQL. If anyone has any idea, please help.

Thank you in advance.

Regards,
Gaurav
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Aug 12, 2009 6:25 am    Post subject: Re: Try Catch in ESQL Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

gaurav.udgir wrote:
I want to throw a user generated exception instead of MB generated exception. I am trying to get something similar to try catch(as in java) in ESQL.


Given my very hazy understanding of try catch in Java, wouldn't the ESQL statement THROW USER EXCEPTION be the sort of thing you were looking for?
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
jbanoop
PostPosted: Wed Aug 12, 2009 6:42 am    Post subject: Reply with quote

Chevalier

Joined: 17 Sep 2005
Posts: 401
Location: SC

you can use the try-catch & throw nodes in conjuction to catch the MB exception and then throw it as a user defined one.

The THROWS clause can be used from within ESQL to raise an exception in case of a validation faling or something like that. It is usually not a system exception but the message failing some business validations/checks.

In my understanding there is no provision in ESQL "catch" an exception.

connecting the failure terminal of the node to a throw node and then throwing the user exception from there is also an option.
Back to top
View user's profile Send private message Yahoo Messenger
mqjeff
PostPosted: Wed Aug 12, 2009 6:50 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

jbanoop wrote:
In my understanding there is no provision in ESQL "catch" an exception.


DECLARE HANDLER, in v6.1.
Back to top
View user's profile Send private message
gaurav.udgir
PostPosted: Wed Aug 12, 2009 8:31 am    Post subject: Reply with quote

Apprentice

Joined: 18 May 2009
Posts: 32

Hi,

Thank you for the information. I tried to get the information about the Handler in 6.1 but found that documentation is limited so unable to get how to use it. Could you please help me with an example?

Thank you.

Regards,
Gaurav
Back to top
View user's profile Send private message
jbanoop
PostPosted: Wed Aug 12, 2009 8:52 am    Post subject: Reply with quote

Chevalier

Joined: 17 Sep 2005
Posts: 401
Location: SC

did you try it out in code ?
Please paste the code that you tried out here and that should act as a good starting point.
Back to top
View user's profile Send private message Yahoo Messenger
gaurav.udgir
PostPosted: Wed Aug 12, 2009 8:28 pm    Post subject: Reply with quote

Apprentice

Joined: 18 May 2009
Posts: 32

Hi,

I am trying something like this:

DECLARE testDate DATE;
SET testDate = CAST(InputRoot.XMLNSC.Test.LastUpdateDate AS TIMESTAMP FORMAT 'I');

In the above statement I am validating that the date is in valid ISO format or not. Now I want to throw a user exception if the above statement fails i.e. the date is not in valid ISO Format.

Thank you.

Regards,
Gaurav
Back to top
View user's profile Send private message
Luke
PostPosted: Thu Aug 13, 2009 1:04 am    Post subject: Reply with quote

Centurion

Joined: 10 Nov 2008
Posts: 128
Location: UK

An alternative you might want to consider here is using the DEFAULT parameter in your CAST. You can then check if testDate is set to the DEFAULT value and THROW your own exception.

Of course, if you do it this way, you need to make sure you set the DEFAULT value to something that would never be validly returned by your data. Also, if you're validating a lot of fields, it'll probably be more efficient to use DECLARE HANDLER to catch exceptions.

Cheers
Back to top
View user's profile Send private message
adrao45
PostPosted: Thu Aug 13, 2009 2:31 pm    Post subject: Reply with quote

Novice

Joined: 29 Nov 2004
Posts: 12

Quote:
SET testDate = CAST(InputRoot.XMLNSC.Test.LastUpdateDate AS TIMESTAMP FORMAT 'I');


The below code throws an user exception, if the above statement fails to execute and propagates an exception tree to failure teriminal

Code:
DECLARE EXIT HANDLER FOR SQLSTATE LIKE'S22007' --this is the SQLState if Date time format not valid
BEGIN
     THROW USER EXCEPTION VALUES ('The Date format not valid', InputRoot.XMLNSC.Test.LastUpdateDate );    
END;


If you want to catch unclassified exceptions, use "%" for the SQL state on the last handler of a scope.
Back to top
View user's profile Send private message
Vinnie
PostPosted: Sun Mar 25, 2012 11:00 pm    Post subject: Catching Exception in ESQL Reply with quote

Newbie

Joined: 05 Mar 2012
Posts: 3

If error is thrown using Declare Handler, How to catch the exception in the esql code itself?
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Mon Mar 26, 2012 2:30 am    Post subject: Re: Catching Exception in ESQL Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Vinnie wrote:
If error is thrown using Declare Handler, How to catch the exception in the esql code itself?


DECLARE HANDLER catches exceptions, it doesn't throw them.

THROW throws exceptions, it doesn't catch them.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Try Catch in ESQL
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.