public class ThrowableMessageExample{ public static void main(String[]args){ try{ int result = divide(10,0); } catch(throwable t){ String errorMessage = t.getMessage(); if(errorMessage!=null){ System.out.println("Caught on exception;"+errorMessage); } else{ System.out.println("Caught on exception with no specific message"); } } public static int divide(int c, int y) throws throwable{ if(y==0){ throwable error = new throwable("Divide by zero is not allowed"); throw error; } return x/y; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter