title: Catch exceptions/runtime errors in python
body: <p>I have a web scraping python script that when you run , it asks for a web address. What I want to happen is to validate the users input eg. if it's a valid web address or when there is no input from the user. I have done the <strong>try</strong> and <strong>except</strong> which almost works, it displays the message that I want the user to see but it also returns Traceback calls and I dont want that. I only want to display my custom error message. Could anyone help me to implement this? Here's my code:</p>
  
  <pre><code>import sys, urllib, urllib2
  
  try:
      url= raw_input('Please input address: ')
      webpage=urllib.urlopen(url)
      print 'Web address is valid'
  except:
      print 'No input or wrong url format usage: http://wwww.domainname.com '
  
  def wget(webpage):
          print '[*] Fetching webpage...\n'
          page = webpage.read()
          return page    
  def main():
      sys.argv.append(webpage)
  
      if len(sys.argv) != 2:
          print '[-] Usage: webpage_get URL'
          return
      print wget(sys.argv[1])
  
  if __name__ == '__main__':
      main()
  </code></pre>