Kotlin Interview Question: What happens if an exception is thrown inside an async coroutine, but await() is never called? Answer: Unlike launch, which throws exceptions right away, async holds exceptions in its Deferred result. If you don’t call await(), the exception will go unnoticed. • async returns a Deferred, which captures the exception and only throws it when you call await(). • If await() is never called, the exception sits silently in the Deferred and is effectively ignored. val deferred = async { throw RuntimeException("Something went wrong") } // No await() here, so the exception is never seen. #Kotlin #AndroidDev
Outcome School’s Post
More Relevant Posts
-
Interview Question: Thread.sleep() vs delay() in Kotlin Answer: Thread.sleep() It pauses the execution of the current thread for the specified number of milliseconds. It is Blocking, it blocks the current thread, which means that the thread cannot do any other work while sleeping. delay() It is a suspending function that pauses the execution of the coroutine without blocking the underlying thread. It is Non-Blocking, it suspends the coroutine but allows the thread to be free to execute other coroutines or tasks. Follow Outcome School for knowledge-packed content. #AndroidDev #Kotlin
To view or add a comment, sign in
-
In my latest Medium article, Topic: How does Kotlin’s inline + reified generics work with a real example? I break down this concept step-by-step - from type erasure to how reified makes type checks possible at runtime - with a real, practical code example you can instantly relate to. ✅ You’ll learn: Why normal generics lose type information at runtime How reified unlocks cleaner, safer, and faster code https://lnkd.in/ge_BcdzY #Kotlin #android #medium #androiddev #inline #reified #interview #kotlindev
To view or add a comment, sign in
-
Android Interview Question: What is Kotlin DSL for Gradle? Kotlin DSL (Domain-Specific Language) for Gradle is an alternative to the traditional Groovy for configuring Gradle build scripts. With Kotlin DSL, you can write your Gradle build configurations using the Kotlin programming language instead of Groovy. • Type Safety: It provides compile-time type checking, reducing runtime errors in your build scripts. • Better IDE support with auto-completion, refactoring capabilities, and improved navigation to source code. All Interview Questions and Answers: https://lnkd.in/ghQPvX3P Follow Outcome School for knowledge-packed content. #SoftwareEngineer #AndroidDev #Android #Kotlin
To view or add a comment, sign in
-
-
If you're writing Kotlin, you need to look at Context Parameters. They are the elegant solution for dependency injection and cleaning up function signatures. Stop passing the same Context over and over. This is a massive improvement for readability. Go check it out. Seriously. 👀 This is the link: https://lnkd.in/dfXKswdk #KotlinDev #AndroidDeveloper
To view or add a comment, sign in
-
How Suspend Functions Work Behind the Scenes in Kotlin 🚀 Ever wondered what really happens when you write a suspend function in Kotlin? We often use suspend in coroutines without thinking twice, but under the hood, it's doing something very powerful — and a bit magical 🧙♂️. Let me break it down. 👇 🧵 What really happens when you write: suspend fun fetchData(): String { val result = networkCall() return result } This doesn't compile into a regular function. The Kotlin compiler rewrites it into a state machine. ⚙️Here’s what happens behind the scenes: 🔍 1. The Function Becomes a State Machine Each suspend point (like delay() or a network call) becomes a state in a generated class. The function is split into steps — like a switch-case statement under the hood. 🧠 2. A Continuation Is Created The compiler generates a Continuation object that keeps track of: Where the coroutine was suspended Local variables The label (i.e., which state to resume from) Coroutine context (like the dispatcher) It’s like placing a bookmark in the middle of your function so it can resume later — with full memory of where it left off. 🔁 3. Resume Happens Through invokeSuspend When the coroutine resumes, the Continuation passes control to an invokeSuspend() method, which uses the label to jump to the correct state and continue execution. 🔄 In simple terms: ✅ Coroutine starts 🛑 Hits a suspend → stores state in Continuation, returns ▶️ Coroutine resumes → reads state, continues where it left off 💥 Why This Is Powerful This mechanism allows Kotlin to: Suspend execution without blocking threads Switch between dispatchers easily Scale thousands of coroutines using just a few threads (like with Dispatchers.IO) 🔬 If you’ve ever opened the Kotlin bytecode (Tools > Kotlin > Show Bytecode > Decompile), you’ll see these transformations for yourself — it’s a great way to learn what’s really going on. 💬 Curious to see a visual of how this state machine works or want code examples? Drop a comment or DM — happy to share! #Kotlin #Coroutines #AndroidDev #SuspendFunction #KotlinInternals #MobileDevelopment #ProgrammingTips #AndroidDeveloper #SeniorAndroidDeveloper #Android #AndroidEngineer #AndroidApp #NativeApp #JetpackCompose
To view or add a comment, sign in
-
-
Kotlin & Higher-Order Functions — A Small Shift, Big Impact One thing I love about Kotlin is how it treats functions as first-class citizens. Passing a function as a parameter felt strange at first, but once it clicked — my code became cleaner and more flexible. Instead of repeating logic, I just pass behavior. Example: fun calculate(a: Int, b: Int, op: (Int, Int) -> Int) = op(a, b) Now I can plug in add, subtract, or any custom logic. It’s a small concept, but it changes how you think about reusability. Simple, elegant, Kotlin-ish.
To view or add a comment, sign in
-
💡 The OpenJDK Vector API, now in its 11th incubation, is pushing Java toward true hardware-level performance — using vector computations that compile into optimal CPU instructions. For native app developers, this represents something bigger: 🔹 The blending of language abstraction and machine-level optimization 🔹 The shift toward architectures that harness CPU-specific power 🔹 The rise of performance-tuned frameworks across ecosystems Whether you’re working in Swift, Kotlin, or C++, the same principle applies — native efficiency through intelligent parallelism. The lesson? The future of native development isn’t about raw speed alone; it’s about writing once and letting the system think like the hardware. #NativeDevelopment #OpenJDK #PerformanceEngineering #VectorAPI #CrossPlatform #MobileOptimization
To view or add a comment, sign in
-
💥 Async made simple with Kotlin Coroutines! If you still think “threads” when you hear async — you’re missing out. Coroutines are Kotlin’s superpower that make concurrency clean, readable, and lifecycle-safe. In my latest blog, I’ve covered 👇 ✅ Coroutine setup (Gradle + dependencies) ✅ Using viewModelScope for lifecycle-aware code ✅ Dispatcher choices (Main, IO, Default) ✅ Exception handling & structured concurrency ✅ Real examples + best practices for 2025 🔥 No callbacks. No chaos. Just clean async code. 🔗 Read the full guide: 👉 https://lnkd.in/dhSbHJGP #AndroidDev #Kotlin #Coroutines #JetpackCompose #AndroidStudio #AsyncProgramming #KotlinFlow #30DaysOfCode
To view or add a comment, sign in
-
Default arguments in Swift and Kotlin can make code cleaner - but at what cost? I explore how overusing them can weaken compiler checks, obscure intent, and blur boundaries between layers. Sometimes, being explicit is better. https://lnkd.in/eBdSfb3z #Swift #Kotlin
To view or add a comment, sign in
-
Tech Stack for Android Machine Coding Round Interviews: • MVVM • Kotlin • Coroutines • Flow • ViewModel • Jetpack Compose or XML • Dagger or Hilt • Retrofit • Room Learn from here: https://lnkd.in/gxDRtDMk #androiddev #android #kotlin #interview
To view or add a comment, sign in
-
Founder @ Outcome School | Coder | Teacher | Mentor | Open Source | IIT 2010-14 | Android | Machine Learning | Backend
6d#AndroidDev #Kotlin