Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
Re: qualifying object classes on the fly
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