الفرق بين المراجعتين ل"Ruby/StandardError"
< Ruby
اذهب إلى التنقل
اذهب إلى البحث
(أنشأ الصفحة ب'يُطلق الاستثناء <code>SecurityError</code> عند محاولة تنفيذ عملية قد تكون غير آمنة، عادة عندما يُرفع مست...') |
|||
سطر 1: | سطر 1: | ||
− | + | معظم أخطاء الأنواع تنحدر من الصنف <code>StandardError</code>، كتلة <code>rescue</code> التي لا تحدد صنف <code>Exception</code> بشكل صريح ستُعالج كل أخطاء <code>StandardErrors</code> (دون غيرها).<syntaxhighlight lang="ruby"> | |
− | foo | + | def foo |
− | + | raise "Oups" | |
− | |||
− | |||
end | end | ||
− | + | foo rescue "Hello" #=> "Hello" | |
+ | </syntaxhighlight>من جهة أخرى:<syntaxhighlight lang="ruby"> | ||
+ | require 'does/not/exist' rescue "Hi" | ||
+ | |||
</syntaxhighlight>ستطلق الاستثناء:<syntaxhighlight lang="ruby"> | </syntaxhighlight>ستطلق الاستثناء:<syntaxhighlight lang="ruby"> | ||
− | + | LoadError: no such file to load -- does/not/exist | |
</syntaxhighlight>{{DISPLAYTITLE: صفحة الاستثناء <code>StandardError</code> في روبي}}</noinclude> | </syntaxhighlight>{{DISPLAYTITLE: صفحة الاستثناء <code>StandardError</code> في روبي}}</noinclude> | ||
سطر 14: | سطر 15: | ||
== مصادر == | == مصادر == | ||
− | *[http://ruby-doc.org/core-2.5.1/ | + | *[http://ruby-doc.org/core-2.5.1/StandardError.html قسم الاستثناء StandardError في توثيق روبي الرسمي.] |
مراجعة 11:14، 2 نوفمبر 2018
معظم أخطاء الأنواع تنحدر من الصنف StandardError
، كتلة rescue
التي لا تحدد صنف Exception
بشكل صريح ستُعالج كل أخطاء StandardErrors
(دون غيرها).
def foo
raise "Oups"
end
foo rescue "Hello" #=> "Hello"
من جهة أخرى:
require 'does/not/exist' rescue "Hi"
ستطلق الاستثناء:
LoadError: no such file to load -- does/not/exist