الفرق بين المراجعتين ل"Ruby/Thread/report on exception-i"

من موسوعة حسوب
< Ruby‏ | Thread
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: تابع النسخة <code>report_on_exception‎</code> الخاص بالصنف <code>Thread</code> في روبي}}</noinclude> تصن...')
 
سطر 3: سطر 3:
 
[[تصنيف: Ruby Method]]
 
[[تصنيف: Ruby Method]]
 
[[تصنيف: Ruby Thread]]
 
[[تصنيف: Ruby Thread]]
يعيد التابع <code>report_on_exception</code> حالة تقرير الاستثناء "report on exception". القيمة الافتراضية هي <code>true</code> منذ روبي 2.5.
+
يعيد التابع <code>report_on_exception</code> حالة تقرير الاستثناء "report on exception" للشرط المحلي ( thread-local condition ) [[Ruby/Thread|للمهمة الفرعية]].
  
كل [[Ruby/Thread|المهام الفرعية]] التي يتم إنشاؤها عندما تكون قيمة هذه الراية مساوية للقيمة <code>true</code> ستبعث رسالة على المجرى <code>stderr$</code> إذا أنهى استثناء ما [[Ruby/Thread|المهمة الفرعية]].
+
القيمة الافتراضية عند إنشاء [[Ruby/Thread|المهمة الفرعية]] هي قيمة الراية العامة <code>[[Ruby/Thread/report on exception|report_on_exception]]</code>.
  
يُستخدم هذا التابع  لإمساك الأخطاء في [[Ruby/Thread|المهمة الفرعية]] في وقت مبكر. لكن في بعض الحالات، قد لا ترغب في هذه المخرجات. هناك عدة طرق لتجنب المخرجات الزائدة:
+
انظر أيضا صفحة <code>[[Ruby/Thread/report on exception-3D-i|report_on_exception=‎]]</code>.
* إذا لم يكن الاستثناء مقصودا، فأفضل خيار أمامك هو إصلاح سبب الاستثناء بحيث لا يُطلق بعدها.
 
* إذا لم يكن الاستثناء مقصودًا، فقد يكون من الأفضل معالجته بالقرب من الموضع الذي أطلق منه بدلاً من تركه ينهي [[Ruby/Thread|المهمة الفرعية]].
 
* في حال كان مُؤمّنا (guaranteed)، سيتم ضم (join) [[Ruby/Thread|المهمة الفرعية]]  عبر <code>[[Ruby/Thread/join|join]]</code> أو <code>[[Ruby/Thread/value|value]]</code>، بعد ذلك سيكون من الآمن تعطيل هذا التقرير عبر التعبير <code>Thread.current.report_on_exception = false</code> عند بدء تشغيل [[Ruby/Thread|المهمة الفرعية]]. لكن هذا قد يعالج الاستثناء في وقت متأخر، أو قد لا يٌعالج أبدا في حالة عدم ضم [[Ruby/Thread|المهمة الفرعية]] في حا كانت [[Ruby/Thread|المهمة الفرعية]] الرئيسية (parent thread) معطلة.
 
انظر أيضا صفحة <code>[[Ruby/Thread/report_on_exception-3D|report_on_exception=‎]]</code>.
 
  
يوجد أيضًا تابع نسخة (instance level method) لتعيين هذا الخيار ل[[Ruby/Thread|مهمة فرعية]] معينة، راجع صفحة <code>[[Ruby/Thread/report on exception-i|report_on_exception]]</code>.
+
يوجد أيضًا تابع صنف (class level method) لتعيين هذا الخيار لكل [[Ruby/Thread|المهام الفرعية]]، راجع صفحة <code>[[Ruby/Thread/report on exception|report_on_exception]]</code>.
 
==البنية العامة==
 
==البنية العامة==
 
<syntaxhighlight lang="ruby">report_on_exception→ true or false‎</syntaxhighlight>
 
<syntaxhighlight lang="ruby">report_on_exception→ true or false‎</syntaxhighlight>
 
==القيمة المُعادة==
 
==القيمة المُعادة==
يعيد التابع <code>report_on_exception</code> قيمة منطقية تمثل حالة تقرير الاستثناء "report on exception".  
+
يعيد التابع <code>report_on_exception</code> قيمة منطقية.
 
 
==أمثلة==
 
مثال على استخدام التابع <code>report_on_exception‎</code>:
 
<syntaxhighlight lang="ruby">Thread.new { 1.times { raise } }‎</syntaxhighlight>سينتج هذا المثال المخرجات التالية في المجرى ‎<code>$stderr</code>:<syntaxhighlight lang="ruby">#<Thread:...> terminated with exception (report_on_exception is true):
 
Traceback (most recent call last):
 
        2: from -e:1:in `block in <main>'
 
        1: from -e:1:in `times'‎</syntaxhighlight>
 
 
==انظر أيضا==
 
==انظر أيضا==
* التابع <code>[[Ruby/Thread/raise|raise]]</code>: يطلق التابع <code>raise</code> استثناء من [[Ruby/Thread|مهمة فرعية]] معينة. لا يلزم أن يكون الُمستدعي (caller) من <code>thr</code>. انظر صفحة <code>[[Ruby/Kernel/raise|Kernel#raise]]</code> لمزيد من المعلومات.
+
*التابع <code>[[Ruby/Thread/raise|raise]]</code>: يطلق التابع <code>raise</code> استثناء من [[Ruby/Thread|مهمة فرعية]] معينة. لا يلزم أن يكون الُمستدعي (caller) من <code>thr</code>. انظر صفحة <code>[[Ruby/Kernel/raise|Kernel#raise]]</code> لمزيد من المعلومات.
* التابع <code>[[Ruby/Thread/report_on_exception-3D|report_on_exception=‎]]</code>: يُعيد التابع <code>report_on_exception=‎</code> الحالة الجديدة.
+
*التابع <code>[[Ruby/Thread/report on exception-3D-i|report_on_exception=‎]]</code>: يطبع التابع <code>report_on_exception=‎</code> رسالة في المخرج stderr$ إذا أنهى استثناء ما [[Ruby/Thread|المهمة الفرعية]].
 
==مصادر==
 
==مصادر==
 
*[http://ruby-doc.org/core-2.5.1/Thread.html#method-i-report_on_exception قسم  التابع report_on_exception‎ في الصنف Thread‎ في توثيق روبي الرسمي.]
 
*[http://ruby-doc.org/core-2.5.1/Thread.html#method-i-report_on_exception قسم  التابع report_on_exception‎ في الصنف Thread‎ في توثيق روبي الرسمي.]

مراجعة 23:24، 5 نوفمبر 2018

يعيد التابع report_on_exception حالة تقرير الاستثناء "report on exception" للشرط المحلي ( thread-local condition ) للمهمة الفرعية.

القيمة الافتراضية عند إنشاء المهمة الفرعية هي قيمة الراية العامة report_on_exception.

انظر أيضا صفحة report_on_exception=‎.

يوجد أيضًا تابع صنف (class level method) لتعيين هذا الخيار لكل المهام الفرعية، راجع صفحة report_on_exception.

البنية العامة

report_on_exception true or false

القيمة المُعادة

يعيد التابع report_on_exception قيمة منطقية.

انظر أيضا

مصادر