亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
亚洲欧洲av在线| 欧美经典一区二区| 欧美高清www午色夜在线视频| 色婷婷精品大视频在线蜜桃视频| 成人免费视频app| 91香蕉视频污在线| 欧美群妇大交群中文字幕| 欧美日韩一区二区三区不卡| 欧美丰满美乳xxx高潮www| 精品成a人在线观看| 日韩免费看的电影| 国产精品毛片久久久久久| 夜色激情一区二区| 日韩成人精品在线| 国产白丝网站精品污在线入口| 成人精品一区二区三区中文字幕| 欧美在线不卡视频| 国产欧美一区二区在线| 亚洲综合在线电影| 国产成人福利片| 91麻豆精品国产91久久久久久 | 国产精品视频一二| 首页综合国产亚洲丝袜| 国产精品亚洲成人| 日韩限制级电影在线观看| 国产精品九色蝌蚪自拍| 蜜臀av性久久久久蜜臀aⅴ| 99精品黄色片免费大全| 精品粉嫩aⅴ一区二区三区四区| 亚洲精品视频免费看| 不卡的av网站| 亚洲精品中文在线观看| 国产91对白在线观看九色| 日韩欧美高清在线| 免费不卡在线观看| 欧美日本乱大交xxxxx| 亚洲图片欧美综合| 欧洲精品在线观看| 亚洲国产成人91porn| 欧美伊人精品成人久久综合97 | 国产精品亚洲人在线观看| 欧美一区二区私人影院日本| 亚洲r级在线视频| 欧美日韩国产bt| 美女视频黄 久久| 精品欧美乱码久久久久久1区2区| 蜜臀av在线播放一区二区三区| 欧美精品在线一区二区三区| 免费国产亚洲视频| 精品国产免费人成电影在线观看四季 | 国产精品久久久久7777按摩| eeuss影院一区二区三区| 亚洲欧洲制服丝袜| 欧美一区二区在线免费播放| 国产又黄又大久久| 1区2区3区国产精品| 欧美日韩国产综合久久| 另类调教123区| 亚洲天堂a在线| 欧美不卡一二三| 一本到一区二区三区| 麻豆精品一区二区三区| 欧美国产日韩精品免费观看| 欧美日韩1区2区| av激情亚洲男人天堂| 另类小说色综合网站| 亚洲精品免费看| 国产女人aaa级久久久级| 6080午夜不卡| 欧美亚洲综合久久| 不卡的电影网站| 成人性生交大片免费| 激情综合网av| 琪琪久久久久日韩精品| 五月天精品一区二区三区| 亚洲手机成人高清视频| 亚洲欧洲日韩女同| 欧美国产精品一区二区| 久久精品一区蜜桃臀影院| 精品捆绑美女sm三区| 国产精品午夜免费| 国产亚洲一区二区在线观看| 日韩视频一区二区三区| 欧美一区二区二区| 欧美一区二区人人喊爽| 337p亚洲精品色噜噜| 日韩亚洲欧美中文三级| 久久午夜老司机| 中文字幕在线不卡一区二区三区| 国产女主播在线一区二区| 国产精品国产三级国产aⅴ原创 | 欧美日韩成人激情| 欧美一区二区日韩| 国产网红主播福利一区二区| 亚洲国产精品成人综合| 国产精品初高中害羞小美女文| 中文字幕字幕中文在线中不卡视频| 国产精品免费视频一区| 亚洲欧美日韩中文播放| 麻豆精品一区二区三区| 成人aa视频在线观看| 欧美亚洲国产bt| 国产午夜亚洲精品午夜鲁丝片| 久久精品亚洲精品国产欧美| 一区二区三区91| 国产69精品久久久久777| 色国产综合视频| 久久九九全国免费| 亚洲一区二区免费视频| 国产一区二区三区四区五区美女| 成人99免费视频| 久久久久一区二区三区四区| 丝袜美腿亚洲色图| 91小视频免费看| 中文在线一区二区| 久久精品国产**网站演员| 色天天综合色天天久久| 国产欧美一区二区三区在线看蜜臀| 亚洲资源中文字幕| 91免费国产在线| 国产精品美女久久久久aⅴ| 日本va欧美va欧美va精品| 欧美色图在线观看| 亚洲黄网站在线观看| 91浏览器在线视频| 亚洲精品国产高清久久伦理二区| 国产麻豆精品久久一二三| 欧美疯狂性受xxxxx喷水图片| 1024成人网| 欧美优质美女网站| 一级精品视频在线观看宜春院 | 一区二区在线观看不卡| youjizz国产精品| 中文字幕一区av| 色综合天天综合给合国产| 91精品国产免费| 亚洲成人午夜影院| 日韩一区二区三区视频在线 | 一区二区三区高清| 欧美日韩五月天| 国产在线播放一区三区四| 国产欧美久久久精品影院| 色综合久久综合| 日韩av一级片| 国产三级精品三级在线专区| www.日韩av| 日韩福利视频网| 中文字幕一区二区三区不卡 | 亚洲国产综合人成综合网站| 日韩视频免费观看高清完整版 | 97精品电影院| 日韩电影免费在线看| 中文字幕av一区二区三区高| 精品视频在线看| 99国产精品久久久久| 蜜桃视频一区二区| 亚洲精品第1页| 国产亚洲精品7777| 欧美成人伊人久久综合网| 99国产麻豆精品| 成人h动漫精品一区二| 精油按摩中文字幕久久| 午夜精品久久久久久久久久| 综合色天天鬼久久鬼色| 欧美精品一区二区三区蜜臀| 欧美日韩久久久| 在线观看网站黄不卡| 91视频免费看| 成人中文字幕电影| 成人性生交大片| 国产成人鲁色资源国产91色综| 久久国产精品72免费观看| 亚洲1区2区3区视频| 午夜精品久久久久久久久| 一区二区三区欧美| 亚洲国产一区二区在线播放| 亚洲综合图片区| 亚洲一区在线电影| 日韩精品三区四区| 韩国精品久久久| 国产成人啪免费观看软件| 国产精品亚洲一区二区三区妖精| 国产一区二区女| 成人精品gif动图一区| 波多野结衣中文字幕一区二区三区| 成人av在线网| 欧美高清性hdvideosex| 精品国产髙清在线看国产毛片| 精品国产成人系列| 国产精品看片你懂得| 亚洲综合免费观看高清完整版在线| 日本色综合中文字幕| 国内精品伊人久久久久av一坑 | 国产精品传媒视频| 午夜视频一区二区三区| 黑人精品欧美一区二区蜜桃| 成人精品视频一区二区三区尤物| 欧美色区777第一页| 国产农村妇女毛片精品久久麻豆 | 欧美日韩精品欧美日韩精品一综合|