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 » Catching Java Exception in Esql

Post new topic  Reply to topic
 Catching Java Exception in Esql « View previous topic :: View next topic » 
Author Message
topmahajan
PostPosted: Thu Mar 02, 2017 2:30 pm    Post subject: Catching Java Exception in Esql Reply with quote

Newbie

Joined: 18 Dec 2012
Posts: 7

Hi,

All I am trying to find out if below scenario is possible (I am using IIB 9.0.0.2 version):

1. I am calling a Java Function from esql code

2. If I throw a user exception in Java Function (MbUserException), is it possible to pass this exception back to esql code so that it is treated as exception in esql code ?

Note: Currently we are passing all the exception details from java function in the Environment . (Reference to Environment is passed as a argument while calling Java function from esql). So, I do have the exception details in esql but then I need to check environment and act accordingly.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Mar 02, 2017 3:24 pm    Post subject: Re: Catching Java Exception in Esql Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

topmahajan wrote:
Hi,

All I am trying to find out if below scenario is possible (I am using IIB 9.0.0.2 version):

1. I am calling a Java Function from esql code

2. If I throw a user exception in Java Function (MbUserException), is it possible to pass this exception back to esql code so that it is treated as exception in esql code ?

Note: Currently we are passing all the exception details from java function in the Environment . (Reference to Environment is passed as a argument while calling Java function from esql). So, I do have the exception details in esql but then I need to check environment and act accordingly.

If I remember correctly, you're not allowed an exception for a Java method being called from ESQL...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
topmahajan
PostPosted: Sun Mar 05, 2017 2:42 pm    Post subject: Re: Catching Java Exception in Esql Reply with quote

Newbie

Joined: 18 Dec 2012
Posts: 7

fjb_saper wrote:

If I remember correctly, you're not allowed an exception for a Java method being called from ESQL...

Thanks for reply. I am not able to find any details about this scenario anywhere. So, was not sure and thought to ask in the forum.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Mar 06, 2017 6:29 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

You should be able to catch this exception using the ESQL normal try/catch (which isn't named try/catch).

You might have to convert your Java Exception into an MBUserException in your java code.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
topmahajan
PostPosted: Mon Mar 06, 2017 6:48 pm    Post subject: Reply with quote

Newbie

Joined: 18 Dec 2012
Posts: 7

Sorry, didn't get you exactly what do u mean by using the ESQL normal try/catch (which isn't named try/catch).

Regarding Java Exception, yes I am converting the Java exception to MBUserException. But not able to find, if I throw MBUserExcption in Java function, how I will catch it in ESQL from where I am calling the Java function?
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue Mar 07, 2017 5:04 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

topmahajan wrote:
Sorry, didn't get you exactly what do u mean by using the ESQL normal try/catch (which isn't named try/catch).


I mean that ESQL has a try/catch structure, where you can wrap a set of one or more statements in a block, and if one of those statements throws an exception, you can catch it and process it.

But ESQL doesn't call the block of statements that you wan;t to try with the word "Try", and it doesn't call the exception handling block "catch".

Please refer to the Knowledge Center for more information on how ESQL handles this.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
topmahajan
PostPosted: Thu Mar 09, 2017 4:01 pm    Post subject: Reply with quote

Newbie

Joined: 18 Dec 2012
Posts: 7

Thanks for the reply, I think you are referring to use Handlers in esql, which we can use for catching the exceptions in esql.

But while trying to implement to throw the exception back from Java to esql, I found that we can't throw the exception back from the Java function because I had to add throws MbUserException statement in Java function definition like: public static String getValue(String s1) throws MbUserException.


And this is not allowed and IIB throws below exception if we do this:


File:CHARACTER:F:\build\slot1\S900_P\src\DataFlowEngine\ImbRdl\ImbRdlExternalJava.cpp
Line:INTEGER:1138
Function:CHARACTER:ESQL2JavaMethodResolver::decodeReturnStatus
Type:CHARACTER:
Name:CHARACTER:
Label:CHARACTER:
Catalog:CHARACTER:BIPmsgs
Severity:INTEGER:3
Number:INTEGER:2927
Text:CHARACTER:The Java method has a throws clause


So, I don't think that this scenario can be implemented.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Mar 10, 2017 4:58 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

https://www.ibm.com/support/knowledgecenter/en/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ac30495_.htm

So change your java throws clause to MbException, not MbUserException.

https://www.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ak20700_.htm

So wrap your Java procedure call in a handler block.

If the selected exception is a user exception (that is, it originated in a THROW statement), the SQL code, state, native error, and error text are taken from the first four inserts of the exception, in order. The resulting state value is taken as is (not prefixed by a letter such as "U"). The letter "U" is not used by the broker as an origin indicator. If you want to define a unique SQL state rather than to imitate an existing one, use SQL states starting with the letter "U". If you use SQL states that start with the letter "U", you can write an error handler to match all user-defined and thrown exceptions with a LIKE'U%' operator.

So declare your handler to catch the SQLSTATE that you populate in your MBUserException, per the above rules.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
mgk
PostPosted: Sat Mar 11, 2017 2:21 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1638

The above will not work for ESQL calling Java as currently no Java exceptions can be thrown back from Java to ESQL. This scenario would work for ESQL calling .NET where exceptions are automatically turned back into IIB Exceptions and can therefore be caught in ESQL Handlers. If you need this functionality for ESQL calling Java, you should raise a requirement. In the meantime, you can put an extra String "Out" parameter on your function, catch the exception on the Java side and return a "toString()" of the exception in the additional parameter.

Kind regards.
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
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 » Catching Java Exception 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.