curl: catching exception on connect.

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 30 11:41:44 PST 2014


This is turning out to be a common problem. :)

On 11/30/2014 11:24 AM, Suliman wrote:
 > I can't understand why I am getting exception on next code:
 >
 >      void downloadFile()
 >      {
 >          foreach(link; links)
 >          {
 >              try
 >              {
 >                  writeln(connect(link));
 >              }
 >
 >              catch(Exception msg)
 >              {
 >                  writeln(msg);

In capitals to make a lasting effect: DON'T EVER OUTPUT THE EXCEPTION 
OBJECT!

Otherwise, you will fool yourself and others as if the exception is not 
being caught.

What is happening is that you are actually catching the exception, 
printing on screen and exiting cleanly.

There is no point of printing the exception object itself. Instead, 
print a meaningful message or something else:

         } catch(Exception msg) {
             import std.string;
             writeln(format("Failed to download '%s'.", link));
         }

Ali



More information about the Digitalmars-d-learn mailing list