comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: qualifying object classes on the fly
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: qualifying object classes on the fly [message #83630] Fri, 15 March 2013 11:41
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 3/15/13 11:00 AM, kagoldberg@lbl.gov wrote:
> Is there an accepted method, or an available function, for determining of an object class exists. I'd like to declare an object with the class specified as the argument to obj_new(), and if it fails to find a known class, have the object return as !null or obj_new(). This is the behavior I would like.
>
> o = OBJ_NEW('testclass', /RETURN_NULL_ON_FAIL)
>
> Currently, asking for a non-existent class breaks the program. Some part of me thinks it would be too inelegant to use CATCH for something like this.
>
> Alternately, is there a routine like this:
> result = TEST_OBJ_CLASS('testclass') ?
>
> Thanks
>

Inelegant or not, I think CATCH is the solution for this:

function test_class, classname, _extra=e
compile_opt strictarr

catch, error
if (error ne 0L) then begin
catch, /cancel
return, obj_new()
endif

return, obj_new(classname, _extra=e)
end

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
[Message index]
 
Read Message
Previous Topic: Creating mesh from XYZ points
Next Topic: Re: Findind NANs in unformatted image data

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:29:40 PDT 2025

Total time taken to generate the page: 0.00382 seconds