<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Python, Java, Life, etc

    A blog of technology and life.

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      30 Posts :: 0 Stories :: 9 Comments :: 0 Trackbacks

    Example: The Carp Module

    This useful little module lets you do a better job of analyzing runtime errors-like when your script can't open a file or when an unexpected input value is found. It defines the carp(), croak(), and confess() fuNCtions. These are similar to warn() and die(). However, instead of reported in the exact script line where the error occurred, the fuNCtions in this module will display the line number that called the fuNCtion that generated the error. Confused? So was I, until I did some experimenting. The results of that experimenting can be found in Listing 15.6.

    Load the Carp module.
    Invoke the strict pragma.
    Start the Foo namespace.
    Define the
    foo() fuNCtion.
    Call the
    carp() fuNCtion.
    Call the
    croak() fuNCtion.
    Switch to the main namespace.
    Call the
    foo() fuNCtion.

    Listing 15.6  15LST06.PL-Using the carp() and croak() from the Carp Module
    use Carp;
    use strict;

    package Foo;
    sub foo {
    main::carp("carp called at line " . __LINE__ .
    ",\n but foo() was called");

    main::croak("croak called at line " . __LINE__ .
    ",\n but foo() was called");
    }

    package main;
    foo::foo();


    This program displays:

    carp called at line 9, 

    but foo() was called at e.pl line 18

    croak called at line 10,

    but foo() was called at e.pl line 18

    This example uses a compiler symbol, __LINE__, to iNCorporate the current line number in the string passed to both carp() and croak(). This technique enables you to see both the line number where carp() and croak() were called and the line number where foo() was called.

    The Carp module also defines a confess() fuNCtion which is similar to croak() except that a fuNCtion call history will also be displayed. Listing 15.7 shows how this fuNCtion can be used. The fuNCtion declarations were placed after the foo() fuNCtion call so that the program flow reads from top to bottom with no jumping around.

    Load the Carp module.
    Invoke the strict pragma.
    Call
    foo().
    Define
    foo().
    Call
    bar().
    Define
    bar().
    Call
    baz().
    Define
    baz().
    Call
    Confess().

    Listing 15.7  15LST07.PL-Using confess() from the Carp Module
    use Carp;
    use strict;

    foo();

    sub foo {
    bar();
    }

    sub bar {
    baz();
    }

    sub baz {
    confess("I give up!");
    }

    This program displays:

    I give up! at e.pl line 16

    main::baz called at e.pl line 12

    main::bar called at e.pl line 8

    main::foo called at e.pl line 5

    This daisy-chain of fuNCtion calls was done to show you how the fuNCtion call history looks when displayed. The fuNCtion call history is also called a stack trace. As each fuNCtion is called, the address from which it is called gets placed on a stack. When the confess() fuNCtion is called, the stack is unwound or read. This lets Perl print the fuNCtion call history.

    posted on 2005-02-18 03:49 pyguru 閱讀(559) 評論(0)  編輯  收藏 所屬分類: Perl
    主站蜘蛛池模板: 国产精品免费_区二区三区观看 | 亚洲国产高清在线| 黄色网页在线免费观看| 国产精品公开免费视频| MM1313亚洲精品无码久久| 免费视频中文字幕| WWW国产亚洲精品久久麻豆| 免费a级毛片网站| 一级A毛片免费观看久久精品 | 亚洲欧洲精品在线| 91精品视频免费| 亚洲成a人片在线看| 免费观看的a级毛片的网站| 亚洲国产欧洲综合997久久| 日本人的色道www免费一区| 美女尿口扒开图片免费| 亚洲Av无码乱码在线观看性色 | 精品亚洲福利一区二区| 亚洲一区精品伊人久久伊人 | 亚洲午夜久久久精品电影院| 曰曰鲁夜夜免费播放视频| 亚洲欧美第一成人网站7777| 亚洲国产综合精品一区在线播放| 九九免费观看全部免费视频| 亚洲高清专区日韩精品| 91精品国产免费久久国语麻豆| 精品亚洲成A人无码成A在线观看| 日本19禁啪啪无遮挡免费动图| eeuss影院www天堂免费| 亚洲av日韩av不卡在线观看| 国产免费女女脚奴视频网| 色天使色婷婷在线影院亚洲| 亚洲中文字幕无码一区二区三区| 蜜桃AV无码免费看永久| 亚洲av无码一区二区三区天堂| 在线观看亚洲精品福利片| 99久久精品免费精品国产| 欧美日韩亚洲精品| 亚洲成AV人片在线观看无| 大学生一级特黄的免费大片视频 | 区久久AAA片69亚洲|