---
title: "Why you should never catch throwable in scala"
page_name: "Why You Should Never Catch Throwable In Scala"
type: "blog"
slug: "why-you-should-never-catch-throwable-in-scala"
published_at: "2014-05-05"
modified_at: "2025-05-09"
url: "https://www.sumologic.com/blog/why-you-should-never-catch-throwable-in-scala"
canonical: "https://www.sumologic.com/blog/why-you-should-never-catch-throwable-in-scala"
markdown_url: "https://www.sumologic.com/blog/why-you-should-never-catch-throwable-in-scala.md"
lang: "en"
excerpt: "Most Scala and Java programmers have heard that catching Throwable, a superclass of all exceptions, is evil... Here is a solution..."
---

[ All blogs ](https://www.sumologic.com/blog "blog")

# Why You Should Never Catch Throwable In Scala

[Russell Cohen](#blog-author-block-271)

May 5, 2014

2 min read 

##### Table of contents

 

 

 

 

Scala is a subtle beast and you should heed its warnings. Most Scala and Java programmers have heard that catching Throwable, a superclass of all exceptions, is evil and patterns like the following should be avoided:

nn

n n

nn

n

n [view raw](https://gist.github.com/rcoh/414fcc7a317a454da514/raw/e57389d2c68bb392770c66239c33b54bf4f2e4e1/dangerouspattern.scala)n [dangerouspattern.scala](https://gist.github.com/rcoh/414fcc7a317a454da514#file-dangerouspattern-scala)n hosted with ❤ by [GitHub](https://github.com)n 

n

n

n')

This pattern is absurdly dangerous. Here’s why:

## The Problem

In Java, catching all throwables can do nasty things like preventing the JVM from properly responding to a StackOverflowError or an OutOfMemoryError. Certainly not ideal, but not catastrophic. In Scala, it is much more heinous. Scala uses exceptions to return from nested closures. Consider code like the following:

nn

n n

nn

n

n [view raw](https://gist.github.com/rcoh/11387293/raw/947f82f2078373f35e705fe6469c4f0faaafeb3c/scalaclosures.scala)n [scalaclosures.scala](https://gist.github.com/rcoh/11387293#file-scalaclosures-scala)n hosted with ❤ by [GitHub](https://github.com)n 

n

[AI Instructions](https://www.sumologic.com/ai-instructions.md)
