CodeGym
AI Academy
Promotion
CodeGym University
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme

Lessons

  • Reviews
  • About us
Start
Start learning
Start learning now
  • My Progress
  • Courses
  • University
  • Quest Map
  • Lessons
  • Error contract: exceptions and “error as a value”

    Kotlin SELF
    Level 40, Lesson 0
    We break down how to design an “error contract” in Kotlin: when exceptions are appropriate, and when it’s better to return an error as a value via a sealed class with Ok/ Error variants. We also separately study fail-fast checks require(...) and check(...), the limitations of the null approach, and tie an error policy to application layers (CLI / domain / storage), reinforcing everything with the remove command example.
    Available
  • try/catch as an expression

    Kotlin SELF
    Level 40, Lesson 1
    We’re exploring the idiomatic Kotlin approach: the try/ catch construct returns a value and can be used as an expression (like if and when). Using practical CLI parsing examples, we’ll learn how to produce an Int or Int?, do an early return, write multiple catch blocks in the correct order, keep the “danger zone” narrow, and use finally correctly. At the end: typical mistakes and style guidelines for Kotlin 2.3.
    Available
  • Custom exceptions and the root cause

    Kotlin SELF
    Level 40, Lesson 2
    We break down why an app needs “custom” exceptions, why it’s important not to lose the root cause ( cause), how to do wrapping correctly (caught → added context → threw further), and how require()/ check() differ from domain errors. We reinforce the technique with a mini app: an “expense tracker” with commands add/ list/ exit and clear messages for the user.
    Available
  • Result<T> — how to store the “success/error” status

    Kotlin SELF
    Level 40, Lesson 3
    We break down Result<T> in Kotlin as an explicit “success or error” contract: how to create results via Result.success(...) and Result.failure(...), how to extract values with getOrNull(), exceptionOrNull(), getOrElse { ... }, getOrThrow(), and also how to build CLI flows without a forest of try/ catch using onSuccess and onFailure. In practice, we show how to “wrap” input errors (for example, NumberFormatException) and common pitfalls when people start using Result as a “silencer” for problems.
    Available
  • runCatching: try/catch, onSuccess/onFailure

    Kotlin SELF
    Level 40, Lesson 4
    We break down how runCatching wraps try / catch into Result<T>, how to safely extract a value via getOrNull(), getOrElse { ... }, getOrThrow(), and how to use onSuccess { ... }/ onFailure { ... } for side effects. Using a CLI command-parsing example, we show where runCatching simplifies code and where it leads to “swallowing” errors—and when an honest try / catch reads better.
    Available
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2026 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2026 CodeGym