当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Ruby limit用法及代码示例


本文简要介绍ruby语言中 Thread::Backtrace.Threade::Backtrace::limit 的用法。

用法

Threade::Backtrace::limit → integer

返回由 --backtrace-limit 命令行选项设置的最大回溯长度。默认值是-1,这意味着无限的回溯。如果该值为零或正数,则 Exception#full_message 生成的错误回溯将被缩写,并且多余的行将被 ... 3 levels... 替换

$ ruby -r net/http -e "p Thread::Backtrace.limit; Net::HTTP.get(URI('http://wrong.address'))"
- 1
.../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': Failed to open TCP connection to wrong.address:80 (getaddrinfo: Name or service not known) (SocketError)
    from .../lib/ruby/3.1.0/socket.rb:227:in `foreach'
    from .../lib/ruby/3.1.0/socket.rb:632:in `tcp'
    from .../lib/ruby/3.1.0/net/http.rb:998:in `connect'
    from .../lib/ruby/3.1.0/net/http.rb:976:in `do_start'
    from .../lib/ruby/3.1.0/net/http.rb:965:in `start'
    from .../lib/ruby/3.1.0/net/http.rb:627:in `start'
    from .../lib/ruby/3.1.0/net/http.rb:503:in `get_response'
    from .../lib/ruby/3.1.0/net/http.rb:474:in `get'
.../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': getaddrinfo: Name or service not known (SocketError)
    from .../lib/ruby/3.1.0/socket.rb:227:in `foreach'
    from .../lib/ruby/3.1.0/socket.rb:632:in `tcp'
    from .../lib/ruby/3.1.0/net/http.rb:998:in `connect'
    from .../lib/ruby/3.1.0/net/http.rb:976:in `do_start'
    from .../lib/ruby/3.1.0/net/http.rb:965:in `start'
    from .../lib/ruby/3.1.0/net/http.rb:627:in `start'
    from .../lib/ruby/3.1.0/net/http.rb:503:in `get_response'
    from .../lib/ruby/3.1.0/net/http.rb:474:in `get'
    from -e:1:in `<main>'

$ ruby --backtrace-limit 2 -r net/http -e "p Thread::Backtrace.limit; Net::HTTP.get(URI('http://wrong.address'))"
2
.../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': Failed to open TCP connection to wrong.address:80 (getaddrinfo: Name or service not known) (SocketError)
    from .../lib/ruby/3.1.0/socket.rb:227:in `foreach'
    from .../lib/ruby/3.1.0/socket.rb:632:in `tcp'
     ... 7 levels...
.../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': getaddrinfo: Name or service not known (SocketError)
    from .../lib/ruby/3.1.0/socket.rb:227:in `foreach'
    from .../lib/ruby/3.1.0/socket.rb:632:in `tcp'
     ... 7 levels...

$ ruby --backtrace-limit 0 -r net/http -e "p Thread::Backtrace.limit; Net::HTTP.get(URI('http://wrong.address'))"
0
.../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': Failed to open TCP connection to wrong.address:80 (getaddrinfo: Name or service not known) (SocketError)
     ... 9 levels...
.../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': getaddrinfo: Name or service not known (SocketError)
     ... 9 levels...

相关用法


注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 limit。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。