-1

how to handle the exception with URL connection when there is an "HTTP Error 500 Internal server" error from Twitter API .so how to handle it .i have coded this code in core java class and made a package for Twitter API call.

import java.net.*; 
import java.io.*;

public class getTwitterData {

    public static URLConnection connection;

    public static void main(String[] args) {

        try {
        System.out.println("Hello World!"); // Display the string.
            try {
            URLConnection connection = new URL("Twitter API call ").openConnection();
            InputStream response = connection.getInputStream();
            System.out.println(response);

            }
        }catch(IOException ex) {}
    }    
}
Sai Ye Yan Naing Aye
  • 6,622
  • 12
  • 47
  • 65

1 Answers1

0

response will have http response code, and each response code can be handled differently if you want.

Subin Sebastian
  • 10,870
  • 3
  • 37
  • 42
  • is it same like ???? HttpURLConnection httpConn = (HttpURLConnection)connection; InputStream is; if (httpConn.getResponseCode() >= 400) { is = httpConn.getInputStream(); } else { is = httpConn.getErrorStream(); } – user1393083 Jun 14 '12 at 07:25