[comp.sys.mac.programmer] ResError Bug?

mikeoro@hubcap.clemson.edu (Michael K O'Rourke) (07/05/89)

I am trying to read a PICT resource into my application.  I have a if-then
statment which checks to see if the resource really existed, but it never 
gets called in the error case.

The code is:

var pict : picHandle;

pict := PicHandle(Get1Resource('PICT',pictNumber));
if ResError = noErr then
    { do something}
else
    { handle error }

Well, i went in and found out that ResError ALWAYS returns noErr. What's up?
I assume that Get1Resource works error handling like GetResource since it
doesn't say otherwise. I tried making pictNumber a value i knew corresponded 
to a given PICT and then a value i knew didn't exist.  Both had noErr for
ResError.

Confusedly,
Michael O'Rourke 

Greg@AppleLink.Apple.Com (Greggy) (07/05/89)

In article <5914@hubcap.clemson.edu> mikeoro@hubcap.clemson.edu (Michael K 
O'Rourke) writes:
> I am trying to read a PICT resource into my application.  I have a 
> if-then statment which checks to see if the resource really existed,
> but it never gets called in the error case.
> 
> The code is:
> 
> pict := PicHandle(Get1Resource('PICT',pictNumber));
> if ResError = noErr then
>     { do something}
> else
>     { handle error }
> 
> Well, i went in and found out that ResError ALWAYS returns noErr.
> What's up?

Get[1]Resource will return NIL if the resource is not present.
ResError's "feature" of always returning noErr makes it useless
in this case.

  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  + Greg Marriott               +                    AppleLink: Greg +
  + Just Some Guy               +                                    +
  + "My phone is always busy"   + Internet: Greg@AppleLink.Apple.Com +
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  + Apple Computer, Inc.                                             +
  + 20525 Mariani Ave, MS-46z, Cupertino, CA  95014                  +
  + (408)974-busy                                                    +
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

isle@eleazar.dartmouth.edu (Ken Hancock) (07/06/89)

In article <5914@hubcap.clemson.edu> mikeoro@hubcap.clemson.edu (Michael K O'Rourke) writes:
>I am trying to read a PICT resource into my application.  I have a if-then
>statment which checks to see if the resource really existed, but it never 
>gets called in the error case.
>
>pict := PicHandle(Get1Resource('PICT',pictNumber));
>if ResError = noErr then
>    { do something}
>
>Well, i went in and found out that ResError ALWAYS returns noErr. What's up?

The correct check is:

if (pict <> NIL)  or for C tyes if (pict != NIL )

This, by the way, is in fact documented in inside mac in the
Resource Manager chapter.  If a GetResource call cannot find
the resource, it returns a NIL handle but does not generate
a resource mamager error.

Ken

Ken Hancock  '90                   | BITNET/UUCP/
Personal Computing Ctr Consultant  |   INTERNET:  isle@eleazar.dartmouth.edu
-----------------------------------+----------------------------------------
DISCLAIMER?  I don't get paid enough to worry about disclaimers.

cjp@Apple.COM (Chris Plummer) (07/06/89)

In article <14217@dartvax.Dartmouth.EDU> isle@eleazar.dartmouth.edu (Ken Hancock) writes:
>In article <5914@hubcap.clemson.edu> mikeoro@hubcap.clemson.edu (Michael K O'Rourke) writes:
>>I am trying to read a PICT resource into my application.  I have a if-then
>>statment which checks to see if the resource really existed, but it never 
>>gets called in the error case.
>>
>>pict := PicHandle(Get1Resource('PICT',pictNumber));
>>if ResError = noErr then
>>    { do something}
>>
>>Well, i went in and found out that ResError ALWAYS returns noErr. What's up?
>
>The correct check is:
>
>if (pict <> NIL)  or for C tyes if (pict != NIL )
>
>This, by the way, is in fact documented in inside mac in the
>Resource Manager chapter.  If a GetResource call cannot find
>the resource, it returns a NIL handle but does not generate
>a resource mamager error.


Not quite.  ResError will return noErr if the resource **type** is not
found.  If the resource type is found but the resource is not then
ResError should return resNotFound.  The is all documented in IM I-119.
By the way, if you use the Inside Mac DA, the writeup for GetResource
does not include the note from IM I that talks about ResError returning
noErr if the resource type isn't found.

keith@Apple.COM (Keith Rollin) (07/06/89)

In article <32877@apple.Apple.COM> cjp@Apple.COM (Chris Plummer) writes:
>In article <14217@dartvax.Dartmouth.EDU> isle@eleazar.dartmouth.edu (Ken Hancock) writes:
>>In article <5914@hubcap.clemson.edu> mikeoro@hubcap.clemson.edu (Michael K O'Rourke) writes:
>>>I am trying to read a PICT resource into my application.  I have a if-then
>>>statment which checks to see if the resource really existed, but it never 
>>>gets called in the error case.
>>>
>>>pict := PicHandle(Get1Resource('PICT',pictNumber));
>>>if ResError = noErr then
>>>    { do something}
>>>
>>>Well, i went in and found out that ResError ALWAYS returns noErr. What's up?
>>
>>The correct check is:
>>
>>if (pict <> NIL)  or for C tyes if (pict != NIL )
>>
>>This, by the way, is in fact documented in inside mac in the
>>Resource Manager chapter.  If a GetResource call cannot find
>>the resource, it returns a NIL handle but does not generate
>>a resource mamager error.
>
>Not quite.  ResError will return noErr if the resource **type** is not
>found.  If the resource type is found but the resource is not then
>ResError should return resNotFound.  The is all documented in IM I-119.
>By the way, if you use the Inside Mac DA, the writeup for GetResource
>does not include the note from IM I that talks about ResError returning
>noErr if the resource type isn't found.

We just hashed this out, and I think that we determined that Get(1)Resource
will never return an error if it can't find the resource it is looking for,
the existance of other resources of the same type notwithstanding. This is in
contrast to Get(1)Named Resource, which WILL return resNotFound under the
circumstances that you would expect it to. Please note that Get(1)Resource
will return other error codes when appropriate.

Steve Brecher, Greg Marriott (just some guy), and myself are all in agreement
on this. If you have experience otherwise, please let me know.

------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc.  ---  Developer Technical Support
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions

mikeoro@hubcap.clemson.edu (Michael K O'Rourke) (07/06/89)

In article <32877@apple.Apple.COM>, cjp@Apple.COM (Chris Plummer) writes:
> >This, by the way, is in fact documented in inside mac in the
> >Resource Manager chapter.  If a GetResource call cannot find
> >the resource, it returns a NIL handle but does not generate
> >a resource mamager error.
> 
> 
> Not quite.  ResError will return noErr if the resource **type** is not
> found.  If the resource type is found but the resource is not then
> ResError should return resNotFound.  The is all documented in IM I-119.
> By the way, if you use the Inside Mac DA, the writeup for GetResource
> does not include the note from IM I that talks about ResError returning
> noErr if the resource type isn't found.

Okay. But there IS a resource type of PICT in the file.  It just doesn't have 
the number that i am trying to access.  So according to your description,
it should return resNotFound. It DOESN'T though. Why?

Michael O'Rourke

brecher@well.UUCP (Steve Brecher) (07/07/89)

In article <32877@apple.Apple.COM>, cjp@Apple.COM (Chris Plummer) writes:

> ResError will return noErr if the resource **type** is not found.  If the
> resource type is found but the resource is not then ResError should return
> resNotFound.  The is all documented in IM I-119.

This posting is redundant to Keith Rollin's <32879@apple.Apple.COM>, but I
wanted to explicitly confirm that IM-119 is incorrect on this issue.  To
correct IM's description of GetResource, change "resNotFound" to "noErr".
Given this correction, the following Note, while true, becomes misleading
and can be deleted.

Get1Resource is the same as GetResource in this respect.
-- 

brecher@well.UUCP (Steve Brecher)