I am trying to catch and then again throw a exception in R. So that the client can read the exception and handle it.
I have tried these links, but none of them works
How to return a error message in R?
To be exact I need to rewrite this program in 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;
}
}
}
Here is what I have tried
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 = {
})
}
And this is the correct url
"http://services.odata.org/V4/(S(cscsmmmc110sj01dvwgyolkm))/TripPinServiceRW/People('russellwhyte')/Microsoft.OData.SampleService.Models.TripPin.GetFavoriteAirline"
I need to print HI and the error msg if any there is any error and throw the error.