r/javahelp • • Mar 17 '26

why some exception need catch some not?

im a noobied in java recently i wondering why some throws-exception method like File#createNewFile() need a catch block but Interger.parseInt(String) no need a catch block. could any body anwser it?

5 Upvotes

14 comments sorted by

View all comments

Show parent comment

2

u/vowelqueue Mar 17 '26

After doing some work in Rust I much prefer using the Result/Either style.

The nice thing in that language is that there is good syntactic sugar for the idiom of “give me the valid value if it exists, otherwise return early with the error”. So if you truly want the error to “bubble up” and not deal with it, that can be accomplished easily.

1

u/vu47 Mar 17 '26

Rust has some well-done functional features, but just not quite enough to turn me into a Rustacean. It seems like a very refreshing language overall, though.