Eliminate another warning.
[suif.git] / html / suif1_106.html
blobfe5e0c15f3d0bed51e548f610b277f10aee29d31
1 <HTML>
2 <HEAD>
3 <!-- This HTML file has been created by texi2html 1.54
4 from suif1.texi on 28 April 1999 -->
6 <TITLE>The SUIF Version 1 Library - Error Handling</TITLE>
7 <link href="suif1_107.html" rel=Next>
8 <link href="suif1_105.html" rel=Previous>
9 <link href="suif1_toc.html" rel=ToC>
11 </HEAD>
12 <BODY>
13 <p>Go to the <A HREF="suif1_1.html">first</A>, <A HREF="suif1_105.html">previous</A>, <A HREF="suif1_107.html">next</A>, <A HREF="suif1_113.html">last</A> section, <A HREF="suif1_toc.html">table of contents</A>.
14 <P><HR><P>
17 <H2><A NAME="SEC106" HREF="suif1_toc.html#TOC106">Error Handling</A></H2>
18 <P>
19 <A NAME="IDX748"></A>
20 <A NAME="IDX749"></A>
21 <A NAME="IDX750"></A>
23 </P>
24 <P>
25 The SUIF library includes a number of functions for error handling.
26 These functions handle three kinds of problems: errors, warnings, and
27 assertions. Assertions are tests for things that should never occur in
28 a correct program. Any problem that could potentially occur in a
29 correct program due to bad input or other external conditions should be
30 treated as an error rather than an assertion failure. Warnings are used
31 to report potentially troublesome conditions that are not serious enough
32 to cause a fatal error.
34 </P>
35 <P>
36 <A NAME="IDX751"></A>
37 <A NAME="IDX752"></A>
38 Two macros are available to implement assertions. The <CODE>assert</CODE>
39 macro takes a single expression as an argument. If the expression
40 evaluates to zero, a message is printed showing the current line number,
41 file name, and the expression that failed, and then the <CODE>abort</CODE>
42 function is called to terminate the program. The <CODE>assert_msg</CODE>
43 macro is similar except that it also prints a user-defined message if
44 the assertion fails. Besides the expression to be tested,
45 <CODE>assert_msg</CODE> takes an argument that contains the message to
46 be printed. This second argument must hold the <CODE>printf</CODE> format
47 string and the arguments for the call to <CODE>printf</CODE>, separated by
48 commas. To keep the commas from splitting up the second argument, it
49 must be surrounded by parentheses. For example:
51 </P>
53 <PRE>
54 assert_msg(sym-&#62;parent(), ("no parent for %s", sym-&#62;name()));
55 </PRE>
57 <P>
58 <A NAME="IDX753"></A>
59 <A NAME="IDX754"></A>
60 Errors may be reported using the <CODE>error_line</CODE> function. The
61 <CODE>return_code</CODE> parameter specifies the method of terminating the
62 program. If the return code is negative, the <CODE>abort</CODE> function is
63 called. If it is greater than zero, the <CODE>exit</CODE> function is called
64 with the specified return code. If the return code is zero, the error
65 message will be printed but the program will not terminate. The
66 <CODE>the_node</CODE> parameter is optional and may be set to <CODE>NULL</CODE>. If
67 used, it points to the AST node closest to the point where the error was
68 detected, and the library tries to use it to find and print the
69 corresponding source line number. Finally, the <CODE>fmt</CODE> parameter
70 specifies the <CODE>printf</CODE> format string used to print the error
71 message and any additional parameters are passed on to <CODE>printf</CODE>.
72 The <CODE>verror_line</CODE> function is identical to <CODE>error_line</CODE> except
73 that it passes the variable arguments for <CODE>printf</CODE> using a
74 <CODE>varargs</CODE>-style list. This is just like the standard
75 <CODE>vprintf</CODE> function.
77 </P>
78 <P>
79 <A NAME="IDX755"></A>
80 <A NAME="IDX756"></A>
81 The <CODE>warning_line</CODE> and <CODE>vwarning_line</CODE> functions are just like
82 the corresponding error functions, except that they print warning
83 messages and do not terminate the program. Consequently, they do not
84 have <CODE>return_code</CODE> parameters.
86 </P>
87 <P><HR><P>
88 <p>Go to the <A HREF="suif1_1.html">first</A>, <A HREF="suif1_105.html">previous</A>, <A HREF="suif1_107.html">next</A>, <A HREF="suif1_113.html">last</A> section, <A HREF="suif1_toc.html">table of contents</A>.
89 </BODY>
90 </HTML>