Handle Function Processing Errors
The common types of exceptions that can occur when evaluating MATLAB® functions include:
HTTP errors — Handled using the Python®
httplib.HTTPException
exception. Common reasons for HTTP errors include:Using an incorrect archive name
Using an incorrect function name
Timing out before the function finishes evaluating
MATLAB Runtime errors — Handled using the
matlab.mpsexception.MATLABException
exception. Occurs when the MATLAB Runtime generates an error while evaluating a function.
Your client code should handle these errors gracefully.
HTTP Errors
If your client code experiences any issues when sending data to or receiving data from a
server instance, an httplib.HTTPException
exception is raised. A common
cause for an HTTP error is a name mismatch between deployed artifacts on the server and the
functions called in the client.
For example, deploying the function mutate()
in the archive
mutations
the following results in an error because the server instance
would not be able to resolve the name of the archive.
import httplib
import matlab
from production_server import client
def main()
my_client = client.MWHttpClient("http://localhost:9190")
try:
result = my_client.mutation.mutate("blue",10,12)
...
except httplib.HTTPException as e:
print e
If you deploy the function mutate()
in the archive
mutations
, the following results in an error because the server instance
would not be able to resolve the name of the function.
import httplib
import matlab
from production_server import client
def main()
my_client = client.MWHttpClient("http://localhost:9190")
try:
result = my_client.mutations.mutator("blue",10,12)
...
except httplib.HTTPException as e:
print e
MATLAB Runtime Errors
If an error occurs while the MATLAB Runtime is evaluating a function, a
matlab.mpsexception.MATLABException
exception is raised. The exception
contains the following:
ml_error_message
— Error message returned by the MATLAB Runtimeml_error_identifier
— MATLAB error IDml_error_stack
— MATLAB Runtime stack
This function catches any MATLAB Runtime errors and prints them to the console.
from matlab.production_server import client
from matlab.production_server import mpsexceptions
import sys
def main(size):
my_client = client.MWHttpClient('http://localhost:9190')
try:
data = my_client.magic.mymagic(size)
print data
except mpsexceptions.MATLABException as e:
print 'MATLAB Error: ',e
my_client.close()
See Also
matlab.production_server.client.MWHttpClient