The ability to access Java exceptions from MATLAB was added in R2012b. If I'm not mistaken, prior versions could only catch exceptions in a general manner without specific error information about the Java error.
Example (tested on R2014a):
try
openStream(java.net.URL('http://non.existant'))
catch ME
end
The exception caught is a MATLAB object that wraps the original Java exception:
>> ME
ME =
JavaException with properties:
ExceptionObject: [1x1 java.net.UnknownHostException]
identifier: 'MATLAB:Java:GenericException'
message: 'Java exception occurred:
java.net.UnknownHostException: non.existant
at java.net.AbstractPlainSocketImpl.connect(Unk...'
cause: {}
stack: [0x1 struct]
so we can access the entire error stack trace:
>> printStackTrace(ME.ExceptionObject)
java.net.UnknownHostException: non.existant
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)