Skip to main content
Code Review

Return to Question

deleted 3 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

JSON fetcher for Eclipse plugin — Is this exemplary code for exception handling?

This is a client module of an Eclipse plugin. I am planning to use this code as a "good exception handling" code example in one of my papers. It is for a client module of an Eclipse plugin. How does it look?

HttpURLConnection httpconn=null;
BufferedReader breader=null;
try{ 
 URL url=new URL(this.web_service_url);
 httpconn=(HttpURLConnection)url.openConnection();
 httpconn.setRequestMethod("GET");
 System.out.println(httpconn.getResponseMessage());
 if(httpconn.getResponseCode()==HttpURLConnection.HTTP_OK)
 {
 breader=new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
 String line=null;
 while((line=breader.readLine())!=null)
 {
 jsonResponse+=line;
 }
 //System.out.println(jsonResponse);
 //display_json_results(jsonResponse);
 }
}catch(MalformedURLException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid URL", e.getMessage());
}catch(ProtocolException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid Protocol", e.getMessage());
}
catch(IOException e2){
 Log.info("Failed to access the data"+e2.getMessage());
}
finally{
 try{
 breader.close();}catch(IOException e){
 Log.info("Failed to release resources"+e.getMessage());
 }
 
}

JSON fetcher for Eclipse plugin — Is this exemplary code for exception handling?

I am planning to use this code as a "good exception handling" code example in one of my papers. It is for a client module of an Eclipse plugin. How does it look?

HttpURLConnection httpconn=null;
BufferedReader breader=null;
try{ 
 URL url=new URL(this.web_service_url);
 httpconn=(HttpURLConnection)url.openConnection();
 httpconn.setRequestMethod("GET");
 System.out.println(httpconn.getResponseMessage());
 if(httpconn.getResponseCode()==HttpURLConnection.HTTP_OK)
 {
 breader=new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
 String line=null;
 while((line=breader.readLine())!=null)
 {
 jsonResponse+=line;
 }
 //System.out.println(jsonResponse);
 //display_json_results(jsonResponse);
 }
}catch(MalformedURLException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid URL", e.getMessage());
}catch(ProtocolException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid Protocol", e.getMessage());
}
catch(IOException e2){
 Log.info("Failed to access the data"+e2.getMessage());
}
finally{
 try{
 breader.close();}catch(IOException e){
 Log.info("Failed to release resources"+e.getMessage());
 }
 
}

JSON fetcher for Eclipse plugin

This is a client module of an Eclipse plugin. I am planning to use this code as a "good exception handling" code example in one of my papers. How does it look?

HttpURLConnection httpconn=null;
BufferedReader breader=null;
try{ 
 URL url=new URL(this.web_service_url);
 httpconn=(HttpURLConnection)url.openConnection();
 httpconn.setRequestMethod("GET");
 System.out.println(httpconn.getResponseMessage());
 if(httpconn.getResponseCode()==HttpURLConnection.HTTP_OK)
 {
 breader=new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
 String line=null;
 while((line=breader.readLine())!=null)
 {
 jsonResponse+=line;
 }
 //System.out.println(jsonResponse);
 //display_json_results(jsonResponse);
 }
}catch(MalformedURLException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid URL", e.getMessage());
}catch(ProtocolException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid Protocol", e.getMessage());
}
catch(IOException e2){
 Log.info("Failed to access the data"+e2.getMessage());
}
finally{
 try{
 breader.close();}catch(IOException e){
 Log.info("Failed to release resources"+e.getMessage());
 }
 
}
Reduced excessive indentation. Edited title.
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 478

Exception handling - JSON fetcher for Eclipse plugin — Is this exemplary code examplefor exception handling?

I am planning to use this code as a 'good"good exception handling'handling" code example in one of my papers. It is for a client module of an Eclipse plugin. How does it look?

HttpURLConnection httpconn=null;
BufferedReader breader=null;
try{ 
 URL url=new URL(this.web_service_url);
 httpconn=(HttpURLConnection)url.openConnection();
 httpconn.setRequestMethod("GET");
 System.out.println(httpconn.getResponseMessage());
 if(httpconn.getResponseCode()==HttpURLConnection.HTTP_OK)
 {
 breader=new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
 String line=null;
 while((line=breader.readLine())!=null)
 {
 jsonResponse+=line;
 }
 //System.out.println(jsonResponse);
 //display_json_results(jsonResponse);
 }
}catch(MalformedURLException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid URL", e.getMessage());
}catch(ProtocolException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid Protocol", e.getMessage());
}
catch(IOException e2){
 Log.info("Failed to access the data"+e2.getMessage());
}
finally{
 try{
 breader.close();}catch(IOException e){
 Log.info("Failed to release resources"+e.getMessage());
 }
 
}

Exception handling - code example

I am planning to use this code as a 'good exception handling' code example in one of my papers. It is for a client module of an Eclipse plugin. How does it look?

HttpURLConnection httpconn=null;
BufferedReader breader=null;
try{ 
 URL url=new URL(this.web_service_url);
 httpconn=(HttpURLConnection)url.openConnection();
 httpconn.setRequestMethod("GET");
 System.out.println(httpconn.getResponseMessage());
 if(httpconn.getResponseCode()==HttpURLConnection.HTTP_OK)
 {
 breader=new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
 String line=null;
 while((line=breader.readLine())!=null)
 {
 jsonResponse+=line;
 }
 //System.out.println(jsonResponse);
 //display_json_results(jsonResponse);
 }
}catch(MalformedURLException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid URL", e.getMessage());
}catch(ProtocolException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid Protocol", e.getMessage());
}
catch(IOException e2){
 Log.info("Failed to access the data"+e2.getMessage());
}
finally{
 try{
 breader.close();}catch(IOException e){
 Log.info("Failed to release resources"+e.getMessage());
 }
 
}

JSON fetcher for Eclipse plugin — Is this exemplary code for exception handling?

I am planning to use this code as a "good exception handling" code example in one of my papers. It is for a client module of an Eclipse plugin. How does it look?

HttpURLConnection httpconn=null;
BufferedReader breader=null;
try{ 
 URL url=new URL(this.web_service_url);
 httpconn=(HttpURLConnection)url.openConnection();
 httpconn.setRequestMethod("GET");
 System.out.println(httpconn.getResponseMessage());
 if(httpconn.getResponseCode()==HttpURLConnection.HTTP_OK)
 {
 breader=new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
 String line=null;
 while((line=breader.readLine())!=null)
 {
 jsonResponse+=line;
 }
 //System.out.println(jsonResponse);
 //display_json_results(jsonResponse);
 }
}catch(MalformedURLException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid URL", e.getMessage());
}catch(ProtocolException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid Protocol", e.getMessage());
}
catch(IOException e2){
 Log.info("Failed to access the data"+e2.getMessage());
}
finally{
 try{
 breader.close();}catch(IOException e){
 Log.info("Failed to release resources"+e.getMessage());
 }
 
}
typos and add java tag - make title reflect what the code does, not what is requested with the review.
Source Link
rolfl
  • 98.1k
  • 17
  • 219
  • 419

How good is this exception Exception handling - code example?

I am planning to use this onecode as a good'good exception handlinghandling' code example in one of my paperpapers. It is for a client module of an Eclipse plugin. How does it look?

HttpURLConnection httpconn=null;
 BufferedReader breader=null;
 try{ 
 URL url=new URL(this.web_service_url);
 httpconn=(HttpURLConnection)url.openConnection();
 httpconn.setRequestMethod("GET");
 System.out.println(httpconn.getResponseMessage());
 if(httpconn.getResponseCode()==HttpURLConnection.HTTP_OK)
 {
 breader=new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
 String line=null;
 while((line=breader.readLine())!=null)
 {
 jsonResponse+=line;
 }
 //System.out.println(jsonResponse);
 //display_json_results(jsonResponse);
 }
 }catch(MalformedURLException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid URL", e.getMessage());
 }catch(ProtocolException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid Protocol", e.getMessage());
 }
 catch(IOException e2){
 Log.info("Failed to access the data"+e2.getMessage());
 }
 finally{
 try{
 breader.close();}catch(IOException e){
 Log.info("Failed to release resources"+e.getMessage());
 }
 
 }

How good is this exception handling code example?

I am planning to use this one as a good exception handling code example in one of my paper. It is for a client module of an Eclipse plugin. How does it look?

HttpURLConnection httpconn=null;
 BufferedReader breader=null;
 try{ 
 URL url=new URL(this.web_service_url);
 httpconn=(HttpURLConnection)url.openConnection();
 httpconn.setRequestMethod("GET");
 System.out.println(httpconn.getResponseMessage());
 if(httpconn.getResponseCode()==HttpURLConnection.HTTP_OK)
 {
 breader=new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
 String line=null;
 while((line=breader.readLine())!=null)
 {
 jsonResponse+=line;
 }
 //System.out.println(jsonResponse);
 //display_json_results(jsonResponse);
 }
 }catch(MalformedURLException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid URL", e.getMessage());
 }catch(ProtocolException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid Protocol", e.getMessage());
 }
 catch(IOException e2){
 Log.info("Failed to access the data"+e2.getMessage());
 }
 finally{
 try{
 breader.close();}catch(IOException e){
 Log.info("Failed to release resources"+e.getMessage());
 }
 
 }

Exception handling - code example

I am planning to use this code as a 'good exception handling' code example in one of my papers. It is for a client module of an Eclipse plugin. How does it look?

HttpURLConnection httpconn=null;
 BufferedReader breader=null;
 try{ 
 URL url=new URL(this.web_service_url);
 httpconn=(HttpURLConnection)url.openConnection();
 httpconn.setRequestMethod("GET");
 System.out.println(httpconn.getResponseMessage());
 if(httpconn.getResponseCode()==HttpURLConnection.HTTP_OK)
 {
 breader=new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
 String line=null;
 while((line=breader.readLine())!=null)
 {
 jsonResponse+=line;
 }
 //System.out.println(jsonResponse);
 //display_json_results(jsonResponse);
 }
 }catch(MalformedURLException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid URL", e.getMessage());
 }catch(ProtocolException e){
 MessageDialog.openError(Display.getDefault().getShells()[0], "Invalid Protocol", e.getMessage());
 }
 catch(IOException e2){
 Log.info("Failed to access the data"+e2.getMessage());
 }
 finally{
 try{
 breader.close();}catch(IOException e){
 Log.info("Failed to release resources"+e.getMessage());
 }
 
 }
Source Link
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /