Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to place a fault check for valid URL ?

Posted on 2011-03-25
6
Medium Priority
?
506 Views
Last Modified: 2012-05-11
How can I put a fault check for the following line that it will get a valid URL as an input? in this case the input is ReportPath.

WebConversation wc = new WebConversation();
WebResponse wr = wc.getResponse(ReportPath);

If I don't pass a valid URL then it says"

java.lang.RuntimeException: No protocol specified in URL ''

Thanks,
0
Comment
Question by:Tolgar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 35219524
catch the MalformedURLException

try {
   URL url = new URL(ReportPath);
   // url is valid
   ...
} catch (MalformedURLException ex) {
   // url is bad
   ...
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35219569
You probably want the ability to use a file as well, so try
if(!ReportPath.startsWith("http:") && !ReportPath.startsWith("file:")) {
    ReportPath = "file:/" + ReportPath;
}
WebResponse wr = wc.getResponse(ReportPath);

Open in new window

0
 
LVL 92

Expert Comment

by:objects
ID: 35220552
if you have a file that you want to load then use the following to convert it to a url
http://helpdesk.objects.com.au/java/how-to-convert-a-file-to-a-url
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:CEHJ
ID: 35232803
The exception was already caught for you
0
 

Author Comment

by:Tolgar
ID: 35232864
@ CEHJ:

How?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35232902
>>java.lang.RuntimeException: No protocol specified in URL

Means that the exception was already caught for you. My point is that it's not so much the exception as what is necessary to stop the exception happening that's at issue here
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question