[opencms-dev] catching exceptions...

Jonathan Woods jonathan.woods at scintillance.com
Fri Feb 17 09:59:13 CET 2006


Nigel -

If your catch block catches CmsException, then it _will_ trap CmsExceptions
when they're thrown.

I doubt CmsException would be thrown if there are no matching resources.
Instead, you'd either get a null value for supportItems (not sure if that's
the behaviour of readResources() method) or you'd get a List of size 0.  A
safe way of dealing with this case is as follows:

java.util.List supportItems = cmsObject.readResources
(request.getParameter("category"),CmsResourceFilter.requireType
(cofaSupportType));

if ((supportItems == null) || (supportItems.size() == 0)) { // note that
through lazy evaluation rules, second condition is fortunately not evaluated
if first is true!
	// do something to handle no matches
}
else {
	// handle the matches
}

Jon

-----Original Message-----
From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of Nigel Kersten
Sent: 17 February 2006 08:41
To: The OpenCms mailing list
Subject: [opencms-dev] catching exceptions...

So I'm a bit of a java noob... but how do I catch an exception on a function
like this:

java.util.List supportItems = cmsObject.readResources
(request.getParameter("category"),CmsResourceFilter.requireType
(cofaSupportType));

when there are no resources of that type in request.getParameter
("category").

I've tried using 'try/catch' with it, but that doesn't seem to work.  
How do I trap CmsExceptions like this?

--
Nigel Kersten [Senior Technical Officer] College of Fine Arts, University of
NSW, Australia.
CRICOS Provider Code: 00098G



_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/mailman/listinfo/opencms-dev





More information about the opencms-dev mailing list