捕获(HTTP)异常并再次在R中抛出

时间:2017-09-11 10:50:34

标签: r

我试图捕获然后再次在R中抛出异常。这样客户端就可以读取异常并处理它。

我试过这些链接,但没有一个可以使用

Equivalent of "throw" in R

How to return a error message in R?

确切地说,我需要在R中重写这个程序。

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public class test {
    public static void main(String s[]) throws IOException  {
        URL url;
        try {
            url = new URL("https://google.com");
            InputStream is = url.openConnection().getInputStream();
            System.out.println(is);
        } catch (MalformedURLException e) {
            e.printStackTrace();
            throw e;
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        }
    }
}

这是我试过的

library(bitops)
library(RCurl)
library(stringr)
library(stringi)
library(XML)
library(httr)
library(methods)
library(getPass)
library(OData)
library(xml2)
library(curl)
status <- function() {
  data = tryCatch({
    url = "http://services.odata.org/V4/(S(cscsmmmc110sj01dvwgyolkm))/TripPinServiceRW/People('rufssellwhyte')/Microsoft.OData.SampleService.Models.TripPin.GetFavoriteAirline"
    print(retrieveData(url))
  }, error = function(error_message) {
    print("HI")
    print(error_message)
    return (NA)
  }, finally = {

  })
}

这是正确的网址

http://services.odata.org/V4/(S(cscsmmmc110sj01dvwgyolkm))/TripPinServiceRW/People( 'russellwhyte')/ Microsoft.OData.SampleService.Models.TripPin.GetFavoriteAirline”

如果有任何错误,我需要打印HI和错误消息并抛出错误。

0 个答案:

没有答案