<commit_before>---
type: doc
layout: reference
category: "Syntax"
title: "Exceptions"
---

# Exceptions

## Exception Classes

All exception classes in Kotlin are descendants of the class *Exception*. Every exception has a message, stack trance and an optional cause.

To throw an exception object, use the *throw*{: .keyword } expression

``` kotlin
throw MyException("Hi There!")
```

To catch an exception, use the *try*{: .keyword } expression

``` kotlin
try {
  // some code
}
catch (e : SomeException) {
  // handler
}
finally {
  // optional finally block
}<commit_msg>Update exceptions.md<commit_after>---
type: doc
layout: reference
category: "Syntax"
title: "Exceptions"
---

# Exceptions

## Exception Classes

All exception classes in Kotlin are descendants of the class *Exception*. Every exception has a message, stack trace and an optional cause.

To throw an exception object, use the *throw*{: .keyword } expression

``` kotlin
throw MyException("Hi There!")
```

To catch an exception, use the *try*{: .keyword } expression

``` kotlin
try {
  // some code
}
catch (e : SomeException) {
  // handler
}
finally {
  // optional finally block
}
{'fraction_non_alphanumeric': 0.11810344827586207, 'fraction_numerical': 0.0, 'mean_word_length': 3.982832618025751, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4093968', 'n_tokens_mistral': 347, 'n_tokens_neox': 335, 'n_words': 139}