This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes catching warnings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "catching warnings" Watch "catching warnings" New topic
Author

catching warnings

Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hello,

Is it possible to catch "warnings" like we catch exceptions.

warning is being generated by a third party utility used in our project. I need to handle it.

Thanks,
Neeraj.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
How does the third party utility get executed?
How does the third party utility "tell" you this warning?

If it writes output to standard error stream or standard output stream - that appears in command prompt window, you could probably capture that output and parse it.

Bill
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

I know Eclipse and IRAD display alot of warning. Acutally, ALOT of warnings in my code. I can't catch them programatically.

Perhaps I should take a better look at my code though. Maybe the tool is telling me something.

I don't know your tool or development environment, but I highly doubth there's a mechanism for handling warnings at compile or runtime, although I do enjoy being proven wrong (it happens fairly often).

-Cameron McKenzie
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
If the warnings are produced using some logging tool (for example log4j), you might be able to register your own logger and somehow analyze the warnings.

But warnings aren't a standard mechanism in Java, so we need to know how those warnings are produced to give you more useful hints.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Also, however this third-party tool works, I'm pretty sure it won't be like catching an exception. Throwing an exception implies that the application is not going to continue processing whatever it's supposed to process; instead, execution will resume at the appropriate catch block (if there is one). However the term "warning" indicates that, although there may be a problem of some sort, the application will not stop processing, but will instead keep going. So throwing an exception would be an inappropriate response for anything which is described as a "warning".
[ January 01, 2007: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hello,

Thanks for your inputs. I am trying to implement JBoss cache in my project. Warning is thrown by class file from JBoss, when it is unable to find a particular node. Though I was catching the exception, when there is some problem in deleting the node by JBOSS. it is not reaching the catch block, it just throws a warning and continues. I need some help on it.

Thanks,
Neeraj.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
it just throws a warning and continues.


Seems to me that no "warning" object is "thrown" - a warning message is written.

Therefore the question is: WHERE is the message written and can you intercept and parse it? What do the JBoss cache docs have to say?

Bill
[ January 03, 2007: Message edited by: William Brogden ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10069
    
163

Originally posted by Neeraj Vij:
Though I was catching the exception, when there is some problem in deleting the node by JBOSS. it is not reaching the catch block, it just throws a warning and continues.



AFAIK, JBossCache uses log4j to log messages. Why would you want to rely on those warning messages? Instead there's a API in JBossCache named



which tells you whether a node exists or not


[My Blog] [JavaRanch Journal]
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
thanks for your inputs.

warning message is coming in the logs on the console. I am unable to find a way to capture that warning message.

Thanks,
Neeraj.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
It seems that the Original Poster is mis-using terms like "catch", which have a very specific meaning in Java.

However, for readers' interest, I thought I'd point out that other languages do have a programmatic mechanism for dealing with warnings. My boss was telling me about it, so it was probably in some flavours of Lisp. I believe that handling of warnings is optional and execution resumes from the same point after any handler has run. Sounds a Good Thing (TM). If anyone can tell me more, I'd be (somewhat) interested to know.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10069
    
163

Originally posted by Peter Chase:
It seems that the Original Poster is mis-using terms like "catch", which have a very specific meaning in Java.



Exactly. Not only that, the word Warning is also being misunderstood in this context. The Warning that the poster is refering to is just a level in log4j to log messages. Also relying on those messages (which can be turned off anytime using log4j configurations) for doing some business logic does not seem right. Just my thoughts.
 
Consider Paul's rocket mass heater.
 
subject: catching warnings