本文簡要介紹ruby語言中 Errno模塊
的用法。
Ruby 異常對象是 Exception
的子類。但是,操作係統通常使用純整數報告錯誤。 Module
Errno
是動態創建的,用於將這些操作係統錯誤映射到 Ruby 類,每個錯誤號生成自己的 SystemCallError
子類。由於子類是在模塊 Errno
中創建的,因此它的名稱將以 Errno::
開頭。
Errno::
類的名稱取決於 Ruby 運行的環境。在典型的 Unix 或 Windows 平台上,有 Errno
類,例如 Errno::EACCES、Errno::EAGAIN、Errno::EINTR 等。
對應於特定錯誤的整數操作係統錯誤號可用作類常量 Errno::
error
::Errno
。
Errno::EACCES::Errno #=> 13
Errno::EAGAIN::Errno #=> 11
Errno::EINTR::Errno #=> 4
您的特定平台上的操作係統錯誤的完整列表可用作 Errno
的常量。
Errno.constants #=> :E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, ...
相關用法
- Ruby ErrorHighlight.spot用法及代碼示例
- Ruby ERB.location=用法及代碼示例
- Ruby Enumerable.any?用法及代碼示例
- Ruby Enumerable min_by()用法及代碼示例
- Ruby Enumerable each_witth_object()用法及代碼示例
- Ruby Enumerable.slice_before用法及代碼示例
- Ruby Enumerable each_cons()用法及代碼示例
- Ruby Enumerator each_with_index用法及代碼示例
- Ruby Encoding.compatible?用法及代碼示例
- Ruby Enumerable.uniq用法及代碼示例
- Ruby Enumerator each_with_object用法及代碼示例
- Ruby ERBIO類用法及代碼示例
- Ruby ENV.empty?用法及代碼示例
- Ruby Enumerable uniq()用法及代碼示例
- Ruby Enumerable.find_all用法及代碼示例
- Ruby Enumerator.peek_values用法及代碼示例
- Ruby Enumerable.max用法及代碼示例
- Ruby Enumerable.map用法及代碼示例
- Ruby Enumerable min()用法及代碼示例
- Ruby Enumerable.min_by用法及代碼示例
- Ruby Enumerable.find_index用法及代碼示例
- Ruby Enumerator類用法及代碼示例
- Ruby Enumerable find_index()用法及代碼示例
- Ruby ENV.delete_if用法及代碼示例
- Ruby Enumerable find_all()用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Errno模塊。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。