التابع report_on_exception=‎ الخاص بالصنف Thread في روبي

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث

يُعيد التعبيرreport_on_exception =‎ الحالة الجديدة. عند إعطائه القيمة true، سترث كل المهام الفرعية التي تم إنشاؤها لاحقا الشرط (condition) وتبعث رسالة على المجرى ‎$stderr إذا أدى استثناء ما إلى إنهاء مهمة فرعية.

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

يوجد أيضًا تابع نسخة (instance level method) لتعيين هذا الخيار لمهمة فرعية معينة، راجع report_on_exception=‎.

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

report_on_exception= boolean true or false

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

يُعيد التعبيرreport_on_exception =‎ قيمة منطقية تمثل الحالة الجديدة.

أمثلة

مثال على استخدام التابع report_on_exception=‎:

Thread.report_on_exception = true
t1 = Thread.new do
  puts  "In new thread"
  raise "Exception from thread"
end
sleep(1)
puts "In the main thread"

هذا سوف ينتج:

In new thread
#<Thread:...prog.rb:2> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
prog.rb:4:in `block in <main>': Exception from thread (RuntimeError)
In the main thread‎

انظر أيضا

  • التابع report_on_exception: يعيد التابع report_on_exception الحالة "report on exception".

مصادر