Author |
Message
|
Cogito-Ergo-Sum |
Posted: Tue Jan 18, 2011 9:03 am Post subject: JavaCompute and exceptions. |
|
|
 Master
Joined: 07 Feb 2006 Posts: 293 Location: Bengaluru, India
|
As per the documentation,
Quote: |
If you catch an exception in your code, throw it again, allowing the broker to construct an exception list and propagate the message to the failure terminal, if one is connected. |
I admit, I do not understand the italicised text. Is there a Java class that can be used to throw an exception again ? Or, is it referring to a Throw node ? Or...?
Also, logging errors with severity as Error is not the same as throwing an exception. Is this correct ? _________________ ALL opinions are welcome.
-----------------------------
Debugging tip:When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
---Sherlock Holmes |
|
Back to top |
|
 |
mqmatt |
Posted: Tue Jan 18, 2011 9:05 am Post subject: |
|
|
 Grand Master
Joined: 04 Aug 2004 Posts: 1213 Location: Hursley, UK
|
Code: |
try {
...
} catch (Exception e) {
...
throw e;
} |
|
|
Back to top |
|
 |
Cogito-Ergo-Sum |
Posted: Tue Jan 18, 2011 10:49 am Post subject: |
|
|
 Master
Joined: 07 Feb 2006 Posts: 293 Location: Bengaluru, India
|
Yes, I am aware of that.
No, that does not allow the Java build to go through.
Hence, my question. _________________ ALL opinions are welcome.
-----------------------------
Debugging tip:When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
---Sherlock Holmes |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jan 18, 2011 11:03 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Cogito-Ergo-Sum wrote: |
Yes, I am aware of that.
No, that does not allow the Java build to go through.
Hence, my question. |
What java build?
Why doesn't it go through? What error message? |
|
Back to top |
|
 |
Cogito-Ergo-Sum |
Posted: Tue Jan 18, 2011 11:21 am Post subject: |
|
|
 Master
Joined: 07 Feb 2006 Posts: 293 Location: Bengaluru, India
|
In the Toolkit, while I am writing the code for the JavaCompute, the IDE forces me to catch every exception that is thrown. Thus, if an exception e is thrown in try block (of the template that comes with a JavaCompute) of evaluate() method, and I catch it such that e is thrown again, my Java code is immediately marked in error. Therefore, the build does not get through.
Code: |
try {
...
} catch (ConfigManagerProxyLoggedException c) {
throw c ;
} |
The throw is marked in error with message as :
Quote: |
Unhandled exception type ConfigManagerProxyLoggedException |
_________________ ALL opinions are welcome.
-----------------------------
Debugging tip:When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
---Sherlock Holmes |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jan 18, 2011 3:29 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Cogito-Ergo-Sum wrote: |
In the Toolkit, while I am writing the code for the JavaCompute, the IDE forces me to catch every exception that is thrown. Thus, if an exception e is thrown in try block (of the template that comes with a JavaCompute) of evaluate() method, and I catch it such that e is thrown again, my Java code is immediately marked in error. Therefore, the build does not get through.
Code: |
try {
...
} catch (ConfigManagerProxyLoggedException c) {
throw c ;
} |
The throw is marked in error with message as :
Quote: |
Unhandled exception type ConfigManagerProxyLoggedException |
|
That is because you are throwing the exception in a method that does not throw exceptions as per it's signature. You need to change your method's signature... or set the syntax checks to be more lax...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jan 18, 2011 6:23 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
fjb_saper wrote: |
That is because you are throwing the exception in a method that does not throw exceptions as per it's signature. |
fjb_saper wrote: |
You need to change your method's signature... |
That's really tough to do on a JavaCompute evaluate() method...
fjb_saper wrote: |
or set the syntax checks to be more lax...  |
Or just don't throw exceptions from the CMP API and instead handle them as needed in terms of reporting the information in them, and then wrapping that in an exception that IS Handled by the JavaCompute node execute() method.  |
|
Back to top |
|
 |
Cogito-Ergo-Sum |
Posted: Tue Jan 18, 2011 7:42 pm Post subject: |
|
|
 Master
Joined: 07 Feb 2006 Posts: 293 Location: Bengaluru, India
|
Quote: |
That is because you are throwing the exception in a method that does not throw exceptions as per it's signature. You need to change your method's signature... |
Quote: |
That's really tough to do on a JavaCompute evaluate() method... |
Yes, I am well aware of the above. Hence, this question.
Quote: |
and then wrapping that in an exception that IS Handled by the JavaCompute node execute() method. |
Can you please show me the skeleton of a sample that does the above ? I could not locate the JavaCompute execute() I did a Google search and looked for javadoc of MbJavaComputeNode. _________________ ALL opinions are welcome.
-----------------------------
Debugging tip:When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
---Sherlock Holmes |
|
Back to top |
|
 |
j.f.sorge |
Posted: Wed Jan 19, 2011 12:54 am Post subject: |
|
|
Master
Joined: 27 Feb 2008 Posts: 218
|
Cogito-Ergo-Sum wrote: |
...
Can you please show me the skeleton of a sample that does the above ? I could not locate the JavaCompute execute() I did a Google search and looked for javadoc of MbJavaComputeNode. |
You may
Code: |
throw new RuntimeException(c) |
or you may do your own code to throw a MbException. _________________ IBM Certified Solution Designer - WebSphere MQ V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Jan 19, 2011 2:47 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Or, despite what the documentation says, you can determine if you actually need your flow logic to treat this condition as an exception. If you do not, then merely catch it and move on - perhaps updating LocalEnvironment or something to indicate the nature of the error to let the downstream node decide what to do.
I believe the part of the documentation you quoted is designed to encourage you to rethrow every MbException, not necessarily every Exception at all. |
|
Back to top |
|
 |
Cogito-Ergo-Sum |
Posted: Wed Jan 19, 2011 8:12 am Post subject: |
|
|
 Master
Joined: 07 Feb 2006 Posts: 293 Location: Bengaluru, India
|
Quote: |
If you do not, then merely catch it and move on - perhaps updating LocalEnvironment or something to indicate the nature of the error to let the downstream node decide what to do. |
Actually, I had been thinking along similar lines. In the catch block, I was planning to build the exception tree and propagate to the Failure terminal (we should be able to get this terminal similar to "out" and "alternate", no ?). The Failure terminal is wired to say, a Compute node that just THROWs an exception; detected and handled by the broker.
Quote: |
I believe the part of the documentation you quoted is designed to encourage you to rethrow every MbException, not necessarily every Exception at all. |
I think, you are right. _________________ ALL opinions are welcome.
-----------------------------
Debugging tip:When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
---Sherlock Holmes |
|
Back to top |
|
 |
Cogito-Ergo-Sum |
Posted: Wed Jan 19, 2011 9:03 pm Post subject: |
|
|
 Master
Joined: 07 Feb 2006 Posts: 293 Location: Bengaluru, India
|
For the people who are following this thread, here is something I found. Throwing exceptions in JavaCompute nodes _________________ ALL opinions are welcome.
-----------------------------
Debugging tip:When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
---Sherlock Holmes |
|
Back to top |
|
 |
Cogito-Ergo-Sum |
Posted: Wed Jan 19, 2011 10:57 pm Post subject: |
|
|
 Master
Joined: 07 Feb 2006 Posts: 293 Location: Bengaluru, India
|
I was able to use the example to fulfil my requirement. Although, it would have been nice if MbUserException allowed us to use message catalogues instead of ResourceBundles. I mean, message catalogues would keep things 'standardized' than have some messages as ResourceBundle and others in catalogues, etc. _________________ ALL opinions are welcome.
-----------------------------
Debugging tip:When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
---Sherlock Holmes |
|
Back to top |
|
 |
Vitor |
Posted: Thu Jan 20, 2011 5:05 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Cogito-Ergo-Sum wrote: |
I was able to use the example to fulfil my requirement. Although, it would have been nice if MbUserException allowed us to use message catalogues instead of ResourceBundles. I mean, message catalogues would keep things 'standardized' than have some messages as ResourceBundle and others in catalogues, etc. |
I'm not going to comment, for reasons connected to my Java experience familar to our regular readers.
But here's a "humm....." question, possibly for a different thread. ResourceBundles seem to be a Java construct that have overlapping functionality with message catalogues. So should a Java Compute Node standardize on the Java functionality or the broker functionality? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Jan 20, 2011 5:11 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Looking at the ResourceBundle: it is an easy way to implement internationalization of customer messages and follows a known pattern for that. Using a message catalog, i guess, is a different way to achieve the same thing. However it also means that all your messages need to exist before your flow is even conceived...
I think both have their place in this development space and the ResourceBundle is just making the User defined message that more flexible.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|