home *** CD-ROM | disk | FTP | other *** search
- /***
- *
- * Exceptions.h
- * Copyright © 1992-1995 by Christopher E. Hyde. All rights reserved.
- *
- * Version: 1.06 11/95
- *
- ***/
-
- #pragma once
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
-
- struct FailInfo {
- long jumpBuf[12]; // old 68K: D2-D7,PC,A2-A4,A6,SP
- FailInfo* nextInfo; // Next in stack.
- };
-
- #ifndef qNoExceptionGlobals
- extern FailInfo* gTopHandler; // Pointer to the top level (most recent) handler
- extern short gFailE;
- extern long gFailM;
- #endif
-
- #define TRY { FailInfo __fi; if (DoTry(&__fi)) {
- #define CATCH Success(); } else {
- #define RETRY Retry(&__fi);
- #define RESIGNAL Failure();
- #define ENDTRY } }
-
-
- extern "C" int DoTry (FailInfo* fi);
- // Call this to set up an exception handler. This pushes your handler onto a stack of exception handlers.
-
- pascal long BuildMessage (short lowWord, short highWord) = 0x2E9F; // MOVE.L (A7)+,(A7)
- // Takes the 2 shorts and combines them into a long failure message.
- // Note that the low-order word is the first parameter.
-
- pascal void Fail (short error);
- #pragma noreturn(Fail)
-
- void Failure (void);
- #pragma noreturn(Failure)
- void Failure (short error, long message);
- #pragma noreturn(Failure)
- // Call this to signal a failure. Control will branch to the most recent
- // exception handler, which will be popped off the handler stack.
-
- inline void Throw (short id) { Fail(id); }
- #pragma noreturn(Throw)
- inline void Throw (short id, long message) { Failure(id, message); }
- #pragma noreturn(Throw)
-
- pascal void FailMemError (void);
- // if (MemError() != noErr) Fail(MemError()); (See the discussion of MemError in Inside Macintosh.)
-
- pascal void FailResError (void);
- // if (ResError() != noErr) Fail(ResError());
-
- pascal void FailNewMessage (short error, long oldMessage, long newMessage);
- // This does: if (oldMessage == 0) oldMessage = newMessage;
- // Failure(err, oldMessage);
-
- pascal void FailNil (void* p);
- // Call this with a pointer/handle; this signals Fail(memFullErr) if p is nil.
-
- pascal void FailNilResource (void* r);
- // Call this with a resource handle; this signals Failure if the handle is nil. The error is
- // either that returned by ResError, or resNotFound if ResError returns no error.
-
- pascal void FailOSErr (OSErr error);
- // Call this with an OSError; signals Fail(error) if error ≠ noErr.
-
- pascal Boolean HandlerExists (FailInfo* testFi);
- // This test returns true if the failure handler exists in the stack from gTopHandler to the outermost handler.
-
- void Success (void);
- void Success (FailInfo* fi);
- // Call this when you want to pop your exception handler. We assume that the programmer passes in the
- // most recent FailInfo record; ie. the one that is the top of the stack. If debugging is on, we check to be sure.
-
- pascal void Retry (FailInfo* fi);
-
- pascal void ProgramBreak (ConstStr255Param grievance);
- // ProgramBreak: Your app can call this when it comes to a situation that you do not expect and cannot
- // handle gracefully. It beeps and calls DebugStr.
-
- pascal void ProgramReport (ConstStr255Param grievance, Boolean brk);
- // Same as ProgramBreak but it only stops in debugger if brk is true.
-