🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #3089

Re: What's wrong with this?

#3089
From: Remy Lebeau (TeamB)
Date: Thu, 17 Nov 2005 07:24
89 lines
3601 bytes
"dzeidzei" <dzeidzei@suolakaivos.com> wrote in message
news:437c19ea$1@newsgroups.borland.com...

> How to protect It from unhandled exeptions?

By not allowing there to be any uncaught exceptions.  Use try...catch blocks
to catch them all.  Especially since you said you are putting the code into
a DLL.  A DLL is not allowed to let exceptions escape into the application.
That is very dangerous.  For example:

    AnsiString HttpsPostSMS(const AnsiString &Url, const AnsiString &Params)
    {
        AnsiString asRet;

        try
        {
            TIdHTTP *HTTP = new TIdHTTP(NULL);
            try
            {
                TIdConnectionInterceptOpenSSL *Intercept = new
TIdConnectionInterceptOpenSSL(IdHTTP);
                Intercept->SSLOptions->Method = sslvSSLv23;
                Intercept->SSLOptions->Mode = sslmClient;
                Intercept->SSLOptions->VerifyDepth = 0;

                HTTP->Intercept = Intercept;
                HTTP->InterceptEnabled = true;

                TStringStream *tsParams = new TStringStream(Params);
                try
                {
                    HTTP->Request->ContentType =
"application/x-www-form-urlencoded";
                    asRet = HTTP->Post(Url, tsParams);
                }
                __finally
                {
                    delete tsParams;
                }
            }
            __finally
            {
                delete HTTP;
            }
        }
        catch(const Exception &e)
        {
            asRet = "Error: " + e.Message;
        }

        return asRet;
    }


You can then use the std::auto_ptr class to clean up the code further:

    #include <memory>

    AnsiString HttpsPostSMS(const AnsiString &Url, const AnsiString &Params)
    {
        try
        {
            std::auto_ptr<TIdHTTP> HTTP(new TIdHTTP(NULL));

            TIdConnectionInterceptOpenSSL *Intercept = new
TIdConnectionInterceptOpenSSL(HTTP.get());
            Intercept->SSLOptions->Method = sslvSSLv23;
            Intercept->SSLOptions->Mode = sslmClient;
            Intercept->SSLOptions->VerifyDepth = 0;

            HTTP->Intercept = Intercept;
            HTTP->InterceptEnabled = true;

            std::auto_ptr<TStringStream> tsParams(new
TStringStream(Params));

            HTTP->Request->ContentType =
"application/x-www-form-urlencoded";
            return HTTP->Post(Url, tsParams);
        }
        catch(const Exception &e)
        {
            return "Error: " + e.Message;
        }
    }


Gambit
Technical Details
Message-ID: <437c306b$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <437b2354$1@newsgroups.borland.com> <437ba8a7$1@newsgroups.borland.com> <437c19ea$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,4165e9ea369c7fad
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <437b2354$1@newsgroups.borland.com> <437ba8a7$1@newsgroups.borland.com> <437c19ea$1@newsgroups.borland.com>
Subject: Re: What's wrong with this?
Date: Wed, 16 Nov 2005 23:24:52 -0800
Lines: 91
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <437c306b$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1132212331 68.69.17.41 (16 Nov 2005 23:25:31 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail