+ 1

How can we catch all kind of exceptions in a single catch block?

23rd Dec 2016, 8:27 PM
Ijas Ahammed
Ijas Ahammed - avatar
4 Answers
+ 4
by simply placing possible errors that may occur in a statement in a try statement or using multiple try statements.
23rd Dec 2016, 8:43 PM
Wen Qin
Wen Qin - avatar
+ 2
try { // code } catch (...){ // code }
23rd Dec 2016, 9:09 PM
@sadface_RL
@sadface_RL - avatar
+ 2
In your "Catch" have a switch with the known values and a "Default" for everything else. Alternatively, you could use if/else if there are not many known values.
23rd Dec 2016, 9:35 PM
Frédéric Charette
Frédéric Charette - avatar
+ 1
try { } catch (Exception ex) { } Exception is the base class from which all kinds of Exceptions are derived. So, this catch block effectively catches all kinds of Exceptions
28th Dec 2016, 7:40 PM
Caffeinated Gamer YT
Caffeinated Gamer YT - avatar