is it possible to write a thrown exception to a file without using try catch blocks?
for example
public static void method() throws Exception, SQLException{
if(Exception is thrown){
write Exception to out.txt;
write SQLException to out.txt;
}
}
or do you have to do:
public static void method(){
try{
...
}catch(Exception ex){
write ex to file;
}catch(SQLException sqlex){
write sqlex to file;
}
}
No.
Where does the Exception come from?
Btw.: You never declare the most abstract exception
Exception
to be thrown. Some RuntimeExceptions can occur nearly everywhere (Nullpointer, OutOfMemory) so it is useless to declare them everywhere. It's just noise.But if you catch it, you usually don't throw, and therefore don't declare at all to throw Exceptions.