Member-only story

Difference Between Throw & Throws In Java

LIU YONGLIANG
3 min readOct 22, 2020

--

Photo by Wil Stewart on Unsplash

Exceptions

Exceptions are things that worth special consideration. This could mean that the execution of some method is “exceptional” because it might result in errors.

We, therefore, handle exceptions in our program to avoid errors. There are two main branches of exceptions, checked and unchecked exceptions.

Summary

Try-catch

One way to deal with known exceptions is to put dangerous code in a try-catch block.

When we catch an exception, we could resolve it by printing out some message to the caller, or we could simply throw the exception at the caller. Actively raising an exception is still considered a way of “handling” exceptions.

--

--

LIU YONGLIANG
LIU YONGLIANG

Written by LIU YONGLIANG

Computer Science Student @ National University of Singapore. Connect with me @ https://www.linkedin.com/in/-yong-/

No responses yet