I have a class which throws a lot of exceptions:     try {        mapper.writeValue(outStream, myVal);    } catch (JsonGenerationException e) {        e.printStackTrace();    } catch (JsonMappingException e) {        e.printStackTrace();    } catch (IOException e) {        e.printStackTrace();    }  I think this looks messy. Is it ok to just catch a generic Exception and not catch each individual exception if within the catch clause of each exception I'm just printing the stack trace?
Catching multiple types of exceptions when writing JSON
java;json;error handling
is it ok to just catch a generic Exception and not catch each individual exception if within the catch clause of each exception im just printing the stack trace ?Yes, it is ok to just catch a generic Exception. The result will be the same if you only print the stack trace, except that catching a generic Exception also catches unchecked (runtime)exceptions such as NullPointerExceptions.But merely printing the stack trace is almost never ok.