هذه صفحة لقطة ثنائية اللغة تم حفظها بواسطة المستخدم في 2025-6-2 22:30 لـ https://app.immersivetranslate.com/pdf-pro/19e3dbb0-07bf-47e3-b366-302e1c419b99/، مقدمة بدعم ثنائي اللغة من قبل الترجمة الغامرة. تعلم كيفية الحفظ؟
Running this code in a JVM environment produces the following output:
ينتج عن تشغيل هذه التعليمات البرمجية في بيئة JVM الإخراج التالي:
Exception in thread "main" java.lang.ArithmeticException: This is an arithmetic exception!
    at MainKt.main(Main.kt:3)
    at MainKt.main(Main.kt)
The first line is the exception description, which includes:
السطر الأول هو وصف الاستثناء ، والذي يتضمن:
  • Exception type: java.lang.ArithmeticException
    نوع الاستثناء: java.lang.ArithmeticException
  • Thread: main  الخيط: رئيسي
  • Exception message: “This is an arithmetic exception!”
    رسالة الاستثناء: "هذا استثناء حسابي!"
Each other line that starts with an at after the exception description is the stack trace. A single line is called a stack trace element or a stack frame:
كل سطر آخر يبدأ ب at بعد وصف الاستثناء هو تتبع المكدس. يسمى السطر الفردي عنصر تتبع المكدس أو إطار المكدس:
  • at MainKt.main (Main.kt:3): This shows the method name (MainKt.main) and the source file and line number where the method was called (Main.kt:3).
    في MainKt.main (Main.kt: 3): يوضح هذا اسم الطريقة (MainKt.main) والملف المصدر ورقم السطر حيث تم استدعاء الطريقة (Main.kt: 3).
  • at MainKt.main (Main.kt): This shows that the exception occurs in the main() function of the Main.kt file.
    في MainKt.main (Main.kt): يوضح هذا أن الاستثناء يحدث في الدالة الرئيسية() لملف Main.kt.

Exception interoperability with Java, Swift, and Objective-C
قابلية التشغيل البيني للاستثناء مع Java وSwift وObjective-C

Since Kotlin treats all exceptions as unchecked, it can lead to complications when such exceptions are called from languages that distinguish between checked and unchecked exceptions. To address this disparity in exception handling between Kotlin and languages like Java, Swift, and Objective-C, you can use the @Throws annotation. This annotation alerts callers about possible exceptions. For more information, see Calling Kotlin from Java and Interoperability with Swift/Objective-C.
نظرا لأن Kotlin يتعامل مع جميع الاستثناءات على أنها غير محددة ، فقد يؤدي ذلك إلى تعقيدات عند استدعاء هذه الاستثناءات من اللغات التي تميز بين الاستثناءات المحددة وغير المحددة. لمعالجة هذا التباين في معالجة الاستثناءات بين Kotlin ولغات مثل Java و Swift و Objective-C، يمكنك استخدام التعليق التوضيحي @Throws. ينبه هذا التعليق التوضيحي المتصلين حول الاستثناءات المحتملة. لمزيد من المعلومات، راجع استدعاء Kotlin من Java وإمكانية التشغيل التفاعلي مع Swift/Objective-C.

Packages and imports  الطرود والواردات

A source file may start with a package declaration:
قد يبدأ الملف المصدر بإعلان حزمة:
package org.example
fun printMessage() { /*...*/ }
class Message { /*...*/ }
// ...
All the contents, such as classes and functions, of the source file are included in this package. So, in the example above, the full name of printMessage() is org.example.printMessage, and the full name of Message is org.example.Message.
يتم تضمين جميع محتويات الملف المصدر ، مثل الفئات والوظائف، في هذه الحزمة. لذلك ، في المثال أعلاه ، الاسم الكامل ل printMessage() هو org.example.printMessage ، والاسم الكامل للرسالة هو org.example.Message.
If the package is not specified, the contents of such a file belong to the default package with no name.
إذا لم يتم تحديد الحزمة، فإن محتويات هذا الملف تنتمي إلى الحزمة الافتراضية بدون اسم.

Default imports  عمليات الاستيراد الافتراضية

A number of packages are imported into every Kotlin file by default:
يتم استيراد عدد من الحزم إلى كل ملف Kotlin بشكل افتراضي:
  • kotlin.*  كوتلين.
  • kotlin.annotation.*
  • kotlin.collections.*
  • kotlin.comparisons.*  kotlin.مقارنات.*
  • kotlin.io.*
  • kotlin.ranges.*
  • kotlin.sequences.*
  • kotlin.text.*
Additional packages are imported depending on the target platform:
يتم استيراد حزم إضافية حسب النظام الأساسي المستهدف: