IllegalArgumentException ex = new IllegalArgumentException("Invalid argument"); ex.printStackTrace();
try { // code that may throw an exception } catch (Exception ex) { OutputStream os = new FileOutputStream("error.log"); ex.printStackTrace(new PrintStream(os)); }These examples use the `java.lang` package library, which is included in the Java standard library.