One feature of Scala is it reuse Java's Exception class hierarchies, but much easier to use. For one thing, it treats Exception as "unchecked" just like RuntimeException, which I think one of the reason it causes Java to be unnecessary verbose. For example when opening a file stream, one way Java can do it is:

public void doFile(File file) throws FileNotFoundException, IOException {  
  FileInputStream fins = null;
try{
fins = new FileInputStream(file);
//process it.
}finally{
if(fins != null){ fins.close(); }
}
}

But in Scala equivalent can be done as follow:
def doFile(file: File): Unit = {  
  val fins = new FileInputStream(file)
try{
//process it.
}finally{
fins.close
}
}

In Scala, you don't need to predefine the "fins" to null then try it, and then check to close in finally block, because if FileInputStream failed, an FileNotFoundException instance will be thrown out of the method, before reaching to the try block. In addition, the Scala user of the doFile method do NOT need to invoke it inside a try/catch block, while Java requires it. This is possible because Exception, or any subclasses are "uncheck" as default in Scala. This mean that the exception will keep throw to next stack frame until it finds a "catcher". If none are found, it will exit main at the end.

Views: 41

Happy 10th year, JCertif!

Notes

Welcome to Codetown!

Codetown is a social network. It's got blogs, forums, groups, personal pages and more! You might think of Codetown as a funky camper van with lots of compartments for your stuff and a great multimedia system, too! Best of all, Codetown has room for all of your friends.

When you create a profile for yourself you get a personal page automatically. That's where you can be creative and do your own thing. People who want to get to know you will click on your name or picture and…
Continue

Created by Michael Levin Dec 18, 2008 at 6:56pm. Last updated by Michael Levin May 4, 2018.

Looking for Jobs or Staff?

Check out the Codetown Jobs group.

 

Enjoy the site? Support Codetown with your donation.



InfoQ Reading List

Presentation: Challenging Google Analytics: Building a Scalable, Cost-Effective User Tracking Service

Alina Krasavina explains how Delivery Hero successfully deprecated Google Analytics and migrated to an internal user tracking platform. She discusses how a simplistic, highly scalable architecture allowed them to handle 10 times more load while capturing 97% of tracking data.

By Alina Krasavina

Java News Roundup: Spring Tools, Helidon, Open Liberty, TomEE, JobRunr, Hibernate, Commonhaus

This week's Java roundup for June 15th, 2026, features news highlighting: point releases of Spring Tools, Helidon, JobRunr and Gradle; the June 2026 edition of Open Liberty; the first milestone release of Apache TomEE 11.0; the first beta release of Hibernate ORM 8.0; Quarkus emergency maintenance releases to address CVE-2026-50559; and four open-source projects join the Commonhaus Foundation.

By Michael Redlich

Podcast: How eBPF Empowers Developers to Observe Inside the Linux Kernel in a Safe and Unintrusive Way

Dan Fineran explores how eBPF has evolved far beyond its roots in packet filtering into a robust, safe way to extend the Linux kernel. He explains how the eBPF "verifier", the security guardrail, enables implementation of deep observability and networking without the risks of traditional kernel modules or the slow upstreaming process.

By Dan Fineran

Article: Understanding ML Model Poisoning: How It Happens and How to Detect It

In this article, the author explores data poisoning as a threat to machine learning systems, covering techniques such as label flipping, backdoors, clean-label poisoning, and gradient manipulation. The article reviews real-world incidents, discusses the challenges of detecting poisoned data, and presents practical defenses, tools, and operational practices for securing ML training pipelines.

By Igor Maljkovic

AWS Graviton5 Reaches General Availability with 192 Cores and Formally Verified VM Isolation

AWS made Graviton5-powered EC2 M9g and M9gd instances generally available with 192 ARM cores, formally verified VM isolation via the Nitro Isolation Engine, and DDR5-8800 memory. ClickHouse reported 36% better performance with zero code changes. Meta committed tens of millions of cores. On-demand pricing is 9% above Graviton4, translating to roughly 15% better price-performance.

By Steef-Jan Wiggers

© 2026   Created by Michael Levin.   Powered by

Badges  |  Report an Issue  |  Terms of Service