Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!wuarchive!udel!haven.umd.edu!cs.wvu.wvnet.edu!cerc.wvu.wvnet.edu!blackwater!vrm From: vrm@blackwater.cerc.wvu.wvnet.edu (Vasile R. Montan) Newsgroups: comp.sys.mac.programmer Subject: Why won't ResError return the right message? Message-ID: <1696@babcock.cerc.wvu.wvnet.edu> Date: 6 May 91 14:40:54 GMT Sender: ab@cerc.wvu.wvnet.edu Reply-To: un020070@vaxa.wvnet.edu Lines: 30 I am writing a program which does a lot of reading and writing of resources (but don't we all? :-). I am trying to write the code as defensively as possible, so that if anything goes wrong, the program will continue as gracefully as possible. For example, here is a snip of code from one of my routines: if OkSoFar then {If we've run in to no problems so far, then get the} begin {resource and typecast it to the right type.} Room := RoomHandle(GetResource('ROOM', RoomNum)); OSResult := ResError; {Check for errors.} if OSResult <> 0 then {If there was an error...} begin doOSErr(OSResult); {then post an alert} OkSoFar := False; {and stop trying to finish the procedure} end; end; As you can see, the soundness of the code relies on ResError to tell if anything has gone wrong. However, I tried testing the code by removing the crucial resource and running this code again. Even though GetResource couldn'thave found the resource (because it wasn't there), ResError returned a 0, indicating that nothing was wrong. Needless to say, the first time I referred to the resource, I got a Bus Error exception, because I was following the invalid handle out into La-La Land. Why didn't ResError tell me there was a problem? --Kurisuto un020070@vaxa.wvnet.edu