亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch13.htm

?? prrl 5 programs codes in the book
?? HTM
?? 第 1 頁 / 共 3 頁
字號:
<HTML>

<HEAD>

<TITLE>Chapter 13  -- Handling Errors and Signals</TITLE>



<META>

</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">

<H1><FONT SIZE=6 COLOR=#FF0000>Chapter&nbsp;13</FONT></H1>

<H1><FONT SIZE=6 COLOR=#FF0000>Handling Errors and Signals</FONT>

</H1>

<HR>

<P>

<CENTER><B><FONT SIZE=5>CONTENTS</FONT></B></CENTER>

<UL>

<LI><A HREF="#CheckingforErrors">

Checking for Errors</A>

<LI><A HREF="#ExampleUsingtheTTFONTSIZEFACECouriererrnoFONTTTFONTSIZEVariableFONT">

Example: Using the <TT>errno</TT>

Variable</FONT></A>

<UL>

<LI><A HREF="#ExampleUsingtheTTFONTSIZEFACECourierorFONTTTFONTSIZELogicalOperatorFONT">

Example: Using the <TT>or</TT>

Logical Operator</FONT></A>

<LI><A HREF="#ExampleUsingtheTTFONTSIZEFACECourierdieFONTTTFONTSIZEFuNCtionFONT">

Example: Using the <TT>die()</TT>

FuNCtion</FONT></A>

<LI><A HREF="#ExampleUsingtheTTFONTSIZEFACECourierwarnFONTTTFONTSIZEFuNCtionFONT">

Example: Using the <TT>warn()</TT>

FuNCtion</FONT></A>

</UL>

<LI><A HREF="#TrappingFatalErrors">

Trapping Fatal Errors</A>

<UL>

<LI><A HREF="#ExampleUsingtheTTFONTSIZEFACECourierevalFONTTTFONTSIZEFuNCtionFONT">

Example: Using the <TT>eval()</TT>

FuNCtion</FONT></A>

</UL>

<LI><A HREF="#WhatIsaSignal">

What Is a Signal?</A>

<UL>

<LI><A HREF="#ExampleHowtoHandleaSignal">

Example: How to Handle a Signal</A>

</UL>

<LI><A HREF="#Summary">

Summary</A>

<LI><A HREF="#ReviewQuestions">

Review Questions</A>

<LI><A HREF="#ReviewExercises">

Review Exercises</A>

</UL>



<HR>

<P>

Most of the examples in this book have been ignoring the fact

that errors can and probably will occur. An error can occur because

the directory you are trying to use does not exist, the disk is

full, or any of a thousand other reasons. Quite often, you won't

be able to do anything to recover from an error, and your program

should exit. However, exiting after displaying a user-friendly

error message is much preferable than waiting until the operating

system or Perl's own error handling takes over.

<P>

After looking at errors generated by fuNCtion calls, we'll look

at a way to prevent certain normally fatal activities-like dividing

by zero-from stopping the execution of your script; this is by

using the <TT>eval()</TT> fuNCtion.

<P>

Then, you'll see what a signal is and how to use the <TT>%SIG</TT>

associative array to create a signal handling fuNCtion.

<H2><A NAME="CheckingforErrors"><FONT SIZE=5 COLOR=#FF0000>

Checking for Errors</FONT></A></H2>

<P>

There is only one way to check for errors in any programming language.

You need to test the return values of the fuNCtions that you call.

Most fuNCtions return zero or false when something goes wrong.

So when using a critical fuNCtion like <TT>open()</TT>

or <TT>sysread()</TT>, checking the

return value helps to ensure that your program will work properly.

<P>

Perl has two special variables-<TT>$?</TT>

and <TT>$!</TT>-that help in finding

out what happened after an error has occurred. The <TT>$?</TT>

variable holds the status of the last pipe close, back-quote string,

or <TT>system()</TT> fuNCtion. The

<TT>$!</TT> variable can be used in

either a numeric or a string context. In a numeric context it

holds the current value of <TT>errno</TT>.

If used in a string context, it holds the error string associated

with <TT>errno</TT>. The variable,

<I>errno</I>, is pre-defined variable that can sometimes be used

to determine the last error that took place. <BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Caution</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

You can't rely on these variables to check the status of pipes, back-quoted strings, or the <TT>system()</TT> fuNCtion when executing scripts under the Windows operating system. My recommendation is to capture the output of the back-quoted string and 
check it directly for error messages. Of course, the command writes its errors to <TT>STDERR</TT> and then can't trap them, and you're out of luck.

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

ONCe you detect an error and you can't correct the problem without

outside intervention, you need to communicate the problem to the

user. This is usually done with the <TT>die()</TT>

and <TT>warn()</TT> fuNCtions.

<H2><A NAME="ExampleUsingtheTTFONTSIZEFACECouriererrnoFONTTTFONTSIZEVariableFONT"><FONT SIZE=5 COLOR=#FF0000>

Example: Using the <TT>errno</TT>

Variable</FONT></FONT></A></H2>

<P>

When an error occurs, it is common practice for UNIX-based fuNCtions

and programs to set a variable called <TT>errno</TT>

to reflect which error has occurred. If <TT>errno=2</TT>,

then your script tried to access a directory or file that did

not exist. Table 13.1 lists 10 possible values the <TT>errno</TT>

variable can take, but there are hundreds more. If you are interested

in seeing all the possible error values, run the program in Listing

13.1.<BR>

<P>

<CENTER><B>Table 13.1&nbsp;&nbsp;Ten Possible Values for </B><TT><B><FONT FACE="Courier">errno</FONT></B></TT></CENTER>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD WIDTH=59><CENTER><I>Value</I></CENTER></TD><TD WIDTH=356><I>Description</I>

</TD></TR>

<TR><TD WIDTH=59><CENTER>1</CENTER></TD><TD WIDTH=356>Operation not permitted

</TD></TR>

<TR><TD WIDTH=59><CENTER>2</CENTER></TD><TD WIDTH=356>No such file or directory

</TD></TR>

<TR><TD WIDTH=59><CENTER>3</CENTER></TD><TD WIDTH=356>No such process

</TD></TR>

<TR><TD WIDTH=59><CENTER>4</CENTER></TD><TD WIDTH=356>Interrupted fuNCtion call

</TD></TR>

<TR><TD WIDTH=59><CENTER>5</CENTER></TD><TD WIDTH=356>Input/output error

</TD></TR>

<TR><TD WIDTH=59><CENTER>6</CENTER></TD><TD WIDTH=356>No such device or address

</TD></TR>

<TR><TD WIDTH=59><CENTER>7</CENTER></TD><TD WIDTH=356>Arg list too long

</TD></TR>

<TR><TD WIDTH=59><CENTER>8</CENTER></TD><TD WIDTH=356>Exec format error

</TD></TR>

<TR><TD WIDTH=59><CENTER>9</CENTER></TD><TD WIDTH=356>Bad file descriptor

</TD></TR>

<TR><TD WIDTH=59><CENTER>10</CENTER></TD><TD WIDTH=356>No child processes

</TD></TR>

</TABLE>

</CENTER>

<P>

<P>



<IMG SRC="pseudo.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/pseudo.gif" BORDER=1 ALIGN=RIGHT><p>

<BLOCKQUOTE>

<I>Loop from 1 to 10,000 using </I><TT><I>$!</I></TT><I>

as the loop variable.<BR>

Evaluate the </I><TT><I>$!</I></TT><I>

variable in a string context so that </I><TT><I>$errText</I></TT><I>

is assigned the error message associated with the value of </I><TT><I>$!</I></TT><I>.

<BR>

Use </I><TT><I>chomp()</I></TT><I>

to eliminate possible newlines at the end of an error message.

Some of the messages have newlines, and some don't.<BR>

Print the error message if the message is not </I><TT><I>Unknown

Error</I></TT><I>. Any error value not used by the system

defaults to </I><TT><I>Unknown Error</I></TT><I>.

Using the if statement modifier ensures that only valid error

messages are displayed.</I>

</BLOCKQUOTE>

<HR>

<BLOCKQUOTE>

<B>Listing 13.1&nbsp;&nbsp;13LST01.PL-A Program to List All Possible

Values for </B><TT><I><B><FONT FACE="Courier">errno<BR>

</FONT></B></I></TT>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

for ($! = 1; $! &lt;= 10000; $!++) {

    $errText = $!;

    chomp($errText);

    printf(&quot;%04d: %s\n&quot;, $!, $errText) if $! ne &quot;Unknown Error&quot;;

}

</PRE>

</BLOCKQUOTE>

<HR>

<P>

Under Windows 95, this program prints 787 error messages. Most

of them are totally unrelated to Perl.

<H3><A NAME="ExampleUsingtheTTFONTSIZEFACECourierorFONTTTFONTSIZELogicalOperatorFONT">

Example: Using the <TT>or</TT>

Logical Operator</FONT></A></H3>

<P>

Perl provides a special logical operator that is ideal for testing

the return values from fuNCtions. You may recall that the <TT>or</TT>

operator will evaluate only the right operand if the left operand

is false. Because most fuNCtions return false when an error occurs,

you can use the <TT>or</TT> operator

to control the display of error messages. For example:

<BLOCKQUOTE>

<PRE>

chdir('/user/printer') or print(&quot;Can't connect to Printer dir.\n&quot;);

</PRE>

</BLOCKQUOTE>

<P>

This code prints only the error message if the program can't change

to the <TT>/user/printer</TT> directory.

Unfortunately, simply telling the user what the problem is, frequently,

is not good enough. The program must also exit to avoid compounding

the problems. You could use the comma operator to add a second

statement to the right operand of the <TT>or</TT>

operator. Adding an <TT>exit()</TT>

statement to the previous line of code looks like this:

<BLOCKQUOTE>

<PRE>

chdir('/usr/printer') or print(&quot;failure\n&quot;), exit(1);

print(&quot;success\n&quot;);

</PRE>

</BLOCKQUOTE>

<P>

I added the extra <TT>print</TT> statement

to prove that the script really exits. If the printer directory

does not exist, the second <TT>print</TT>

statement is not executed.<BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Note</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

At the shell or DOS, a zero return value means that the program ended successfully. While inside a Perl script, a zero return value frequently means an error has occurred. Be careful when dealing with return values; you should always check your 
documentation. </BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

Using the comma operator to execute two statements instead of

one is awkward and prone to misinterpretation when other programmers

look at the script. Fortunately, you can use the <TT>die()</TT>

fuNCtion to get the same fuNCtionality.

<H3><A NAME="ExampleUsingtheTTFONTSIZEFACECourierdieFONTTTFONTSIZEFuNCtionFONT">

Example: Using the <TT>die()</TT>

FuNCtion</FONT></A></H3>

<P>

The <TT>die()</TT> fuNCtion is used

to quit your script and display a message for the user to read.

Its syntax is

<BLOCKQUOTE>

<PRE>

die(LIST);

</PRE>

</BLOCKQUOTE>

<P>

The elements of <TT>LIST</TT> are

printed to <TT>STDERR</TT>, and then

the script will exit, setting the script's return value to <TT>$!</TT>

(<TT>errno</TT>). If you were running

the Perl script from inside a C program or UNIX script, you could

then check the return value to see what went wrong.

<P>

The simplest way to use the <TT>die()</TT>

fuNCtion is to place it on the right side of the <TT>or</TT>

operator

<BLOCKQUOTE>

<PRE>

chdir('/user/printer') or die();

</PRE>

</BLOCKQUOTE>

<P>

which displays

<BLOCKQUOTE>

<PRE>

Died at test.pl line 2.

</PRE>

</BLOCKQUOTE>

<P>

if the /user/printer directory does not exist. The message is

not too informative, so you should always iNClude a message telling

the user what happened. If you don't know what the error might

be, you can always display the error text associated with errno.

For example:

<BLOCKQUOTE>

<PRE>

chdir('/user/printer') or die(&quot;$!&quot;);

</PRE>

</BLOCKQUOTE>

<P>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品少妇一区二区三区| 亚洲va国产va欧美va观看| 亚洲一区二区三区不卡国产欧美| 一区二区三区免费看视频| 国产一区二区在线观看免费| 欧美网站大全在线观看| 欧美激情一区在线观看| 久久激情综合网| 欧美综合欧美视频| 亚洲欧洲韩国日本视频| 久久精品国产久精国产爱| 欧美午夜精品一区二区蜜桃| 国产精品成人免费在线| 精品一区二区久久久| 欧美高清视频www夜色资源网| 亚洲免费毛片网站| 粉嫩aⅴ一区二区三区四区五区| 欧美一级视频精品观看| 亚洲国产精品一区二区久久恐怖片| 国产**成人网毛片九色 | 中文字幕在线不卡国产视频| 免费一级欧美片在线观看| 在线观看日韩一区| 亚洲女女做受ⅹxx高潮| 99久久婷婷国产综合精品| 国产欧美精品区一区二区三区| 韩日欧美一区二区三区| 精品欧美乱码久久久久久| 免费在线欧美视频| 日韩一区二区三区电影在线观看| 性欧美大战久久久久久久久| 欧美亚男人的天堂| 亚洲一区二区高清| 欧美亚洲日本一区| 亚洲一二三四久久| 欧美日韩高清在线| 亚洲第一激情av| 欧美精品乱码久久久久久按摩| 婷婷综合另类小说色区| 欧美日韩成人综合在线一区二区 | 欧美日韩综合在线| 亚洲成人在线网站| 7777精品伊人久久久大香线蕉完整版 | 国产精品888| 国产欧美视频在线观看| 99riav久久精品riav| 亚洲高清免费视频| 91麻豆精品国产91| 国产综合久久久久久鬼色| 国产欧美日韩中文久久| 91麻豆国产福利精品| 亚洲一区精品在线| 7777精品伊人久久久大香线蕉完整版 | 精品99一区二区| 成人免费看视频| 亚洲制服欧美中文字幕中文字幕| 欧美视频第二页| 麻豆成人久久精品二区三区小说| 久久久久国产成人精品亚洲午夜 | 国产sm精品调教视频网站| 日韩一区在线看| 在线不卡a资源高清| 免费不卡在线视频| 国产精品麻豆欧美日韩ww| 色伊人久久综合中文字幕| 免费人成在线不卡| 国产精品人成在线观看免费| 欧美视频在线观看一区| 麻豆免费精品视频| 亚洲欧美在线高清| 日韩视频中午一区| 91一区在线观看| 日韩成人精品在线观看| 国产精品毛片久久久久久| 制服丝袜一区二区三区| 99国产精品国产精品久久| 久久国产精品区| 一区二区三区在线观看网站| 欧美本精品男人aⅴ天堂| 99久久伊人精品| 久久99精品久久久久婷婷| 亚洲欧美日韩国产综合| 精品国免费一区二区三区| 色综合久久久久久久久久久| 国产老女人精品毛片久久| 亚洲成人av电影| 亚洲同性gay激情无套| 亚洲精品一区二区三区影院| 欧洲视频一区二区| 波多野洁衣一区| 韩国毛片一区二区三区| 琪琪一区二区三区| 樱桃国产成人精品视频| 亚洲国产精品黑人久久久| 日韩视频在线永久播放| 欧美日韩三级在线| 91欧美一区二区| 成人动漫一区二区三区| 久草热8精品视频在线观看| 偷窥少妇高潮呻吟av久久免费| 亚洲欧美综合色| 国产精品久久久一本精品 | 欧美一区二区黄| 这里是久久伊人| 欧美日韩国产片| 欧美视频一区在线观看| 欧美午夜免费电影| 91豆麻精品91久久久久久| 99免费精品在线| 色综合天天性综合| 日本精品一级二级| 在线观看免费视频综合| 91片黄在线观看| 91豆麻精品91久久久久久| 色久综合一二码| 欧美性色黄大片| 欧美日韩亚洲高清一区二区| 欧美日韩和欧美的一区二区| 欧美日韩在线综合| 这里只有精品99re| 欧美大片国产精品| 久久香蕉国产线看观看99| 久久精品亚洲麻豆av一区二区 | 日韩精品1区2区3区| 欧美a级一区二区| 激情综合色播激情啊| 精品一区二区三区免费视频| 韩日av一区二区| 成人激情免费电影网址| 99国产精品久久久久久久久久| 色婷婷综合在线| 69堂成人精品免费视频| 精品久久久久一区| 国产日韩欧美制服另类| 日韩一区日韩二区| 午夜精品福利一区二区蜜股av| 蜜臀久久99精品久久久久久9| 韩国女主播一区| 91丝袜国产在线播放| 欧美精品v国产精品v日韩精品| 欧美大片一区二区三区| 中文字幕乱码久久午夜不卡| 一区二区在线观看视频在线观看| 日韩二区在线观看| 岛国精品在线观看| 在线一区二区视频| 日韩免费电影网站| 国产精品美女一区二区三区 | 国产精品一色哟哟哟| 91免费在线看| 欧美一区2区视频在线观看| 国产区在线观看成人精品| 亚洲人成精品久久久久久| 日本vs亚洲vs韩国一区三区二区 | 欧美人牲a欧美精品| 国产日韩欧美a| 性久久久久久久| 国产成人精品三级麻豆| 欧美日韩中文字幕精品| 精品国产3级a| 亚洲国产精品自拍| 国产福利精品一区二区| 欧美日韩国产精品成人| 欧美国产欧美亚州国产日韩mv天天看完整| 亚洲一级不卡视频| 福利一区二区在线观看| 欧美久久久久久久久久| 中文字幕欧美一| 精油按摩中文字幕久久| 欧洲一区二区三区在线| 国产精品少妇自拍| 久久精品99久久久| 欧美久久久久久久久| 国产精品久久久久久久久免费桃花 | 亚洲第一狼人社区| 色综合久久久网| 国产精品久线在线观看| 国产乱理伦片在线观看夜一区| 这里是久久伊人| 亚欧色一区w666天堂| 在线看一区二区| 一区二区三区在线高清| 丁香婷婷综合网| 久久久久久一级片| 久久精品国产免费| 日韩欧美www| 蜜桃av一区二区三区电影| 欧美撒尿777hd撒尿| 亚洲美女免费视频| 成人av在线资源网站| 国产欧美日本一区二区三区| 国产一区啦啦啦在线观看| 日韩视频免费观看高清完整版 | 国产亲近乱来精品视频| 国产一区二区调教| 久久夜色精品一区| 精品一区二区在线播放| 久久影音资源网| 国产成人免费视频精品含羞草妖精 | 337p亚洲精品色噜噜噜|