⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 except.n

📁 早期freebsd实现
💻 N
字号:
.TH EXCEPT 3 Stanford.SH NAME(except) raise, raise_sys() \- C exception handling.SH SYNOPSIS.B #include <xnscourier/except.h>.sp.B raise(code, msg).br.B int code;.br.B char *msg;.sp.B raise_sys().spcc ... \-lexcept.SH "EXTENDED C SYNTAX".B DURINGstatement1.B HANDLERstatement2.B END_HANDLER.sp.B E_RETURN(expression.B ).sp.B E_RETURN_VOID.SH DESCRIPTIONThe macros and functions in this package provide a limited amountof exception handling for programming in C.  They provide theability to associate an exception handler to be invoked if anexception is raised during the execution of a statement..PPC syntax is extended by several macros that allow the programmerto associate an exception handler with a statement.  The ``syntax''for this is:.sp.nfDURING statement1 HANDLER statement2 END_HANDLER.fi.spEither or both statement may be a compound statement.If an exception is raised using the.IR raise ()function during.I statement1(or during any functions called by.IR statement1 ),the stack will be unwound and.I statement2will be invoked in the current context.  However, if the exceptionhandler is redeclared in a.I dynamicallyenclosed statement, the current exception handler will be inactive duringthe execution of the enclosed statement..PPDuring the execution of.IR statement2 ,two predefined values may be used:.IR Exception.Code ,an integer, is the value of.I codepassed to the .IR raise ()call which invoked the handler, and.IR Exception.Messageis the value of.IR msg .It is up to the user to define the values used for the exceptioncodes; by convention, small positive integers are interpretedas Unix error codes..PPAs an example of the use of this package, the following ``toy'' codecomputes the quotient of variables f1 and f2, unless f2 is 0.0:.sp.nf	DURING {	    if (f2 == 0.0)	    	raise(DIVIDE_BY_ZERO, "Division by zero attempted");	    quotient = f1/ f2;	} HANDLER	    switch (Exception.Code) {	    case DIVIDE_BY_ZERO:	    	return(HUGE);		break;	    default:	    	printf("Unexpected error %s\\n", Exception.Message);	    }	END_HANDLER.fi.PPIf a handler does not want to take responsibility for an exception,it can ``pass the buck'' to the dynamically enclosing exceptionhandler by use of the.I RERAISEmacro, which simply raises the exception that invoked the handler.Of course, it is possible that there is no higher-level handler.The programmer can control the action in this case by setting theexternal int.I ExceptModeto some (bit-wise OR'd) combination of the following constants:.IP "EX_MODE_REPORT" 1.5iPrint a message on stderr if an exception is not caught.  If thisis not set, no message is printed..IP "EX_MODE_ABORT" 1.5iCalls the.IR abort (3)routine if an exception is not caught.  If this is not set,.IR exit (3)is called, with the exception code as an argument..PPThe default value for.I ExceptModeis zero..SH RESTRICTIONS.B THESE RESTRICTIONS ARE IMPORTANT;YOU WILL SUFFER IF YOU DISOBEY THEM..PPDuring the execution of.IR statement1,no transfers out of the statement are allowed, except as noted here.Execution of a compound.I statement1 must ``run off the end'' of the block.  This means that.I statement1may not include a.B returnor.BR goto ,or a.B breakor.B continuethat would affect a loop enclosing the.I DURING ... END_HANDLERblock.  The.I statement1may include a call to.IR raise ()(but not.IR RERAISE ),.IR exit (3),and any statement at all may be used in a function called..PPIf you wish to use a.B returnwithin.IR statement1 ,you must instead use.I E_RETURN()to return a value,or.I E_RETURN_VOIDif the enclosing function is declared.BR void .These two macros may be used.I onlyin the (lexically) outermost.I statement1of a function, and nowhere else..PPThere are no restrictions on what may be done inside the.I statement2part of a handler block, except that it is subject to theabove constraints if it is lexically enclosed in the.I statement1part of another handler..PPAs an aid to Unix programmers, the.IR raise_sys ()function is provided.  It is used exactly as.IR raise ()is, except that it uses the global.IR errno (3)to produce the exception code and message..SH SEE ALSOerrno(3), setjmp(3).SH AUTHORJeffrey Mogul (Stanford).SH BUGSDue to a limitation of the.IR setjmp (3)implementation,.B registervariables which are actually stored in registers (and this is notalways easy to determine, and especially is not portable) are restoredto the values they had upon entering.I statement1when the handler.RI ( statement2 )is invoked.  All other data keeps whatever values they were assignedduring the (interrupted) execution of.IR statement1 .A good rule to follow is that you should not rely on the values ofvariables declared.B register(in the current block) after an exception has been caught.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -