This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page. class

Superclasses: MException

Exception thrown by HTTP services


The HTTPException class contains information about errors.

The RequestMessage.send method throws an HTTP exception when an error occurs after it attempts to send a message. For instance, the method throws an exception when:

  • Something fails during transmission and the server does not receive the message. Possible causes of failure include a network problem, timeout, or bad URI.

  • The server receives the message, but something fails while it is sending a response.

  • The server receives the message and sends a response, but the response cannot be converted based on its Content-Type. For example, a bad JSON string is received.

If an error occurs before the RequestMessage.send method attempts to send the message, then it throws a standard MException instead.

The HTTPException describes the error in the MException.cause property and returns a history of the transaction. The History property contains the message that was sent and the message that was received, if any.


expand all

Request message as completed, specified as a object. Request contains the last message that was sent or would have been sent. If this message header was successfully sent, then it is the same as the last entry in the History.Request property. Otherwise, the last entry in the History property does not contain the message you attempted to send.



URI for the last message that was sent or would have been sent, specified as a object.



History of the transaction, specified as a vector of objects. History only contains messages whose headers were successfully sent or received. If an exception occurs when sending or receiving a message header, then History does not contain that message. If an error occurs while sending or receiving the payload, or during conversion of the data to or from the payload, then the MessageBody Payload property and/or Data properties might not be set.




collapse all

Send a message to the website in the url variable. This destination returns a message whose Payload property contains an invalid JPEG image for Content-Type image/jpeg.

    resp = RequestMessage().send(url);
catch e
    if isa(e,'')
        response = e.History(end).Response;      
        if ~isempty(response)
            data = response.Body.Data;
            payload = resonse.Body.Payload

The payload variable contains the bytes that were received as a uint8 vector. Since the Content-Type is not character-based, the data variable is empty.

Introduced in R2016b

Was this topic helpful?