why there is no variabel after &

H

hon123456

Dear all,

I have following code:

#include <stdio.h> // for printf
#include <SQLAPI.h> // main SQLAPI++ header

int main(int argc, char* argv[])
{
SAConnection con; // create connection object

try
{
// connect to database
// in this example it is Oracle,
// but can also be Sybase, Informix, DB2
// SQLServer, InterBase, SQLBase and ODBC
con.Connect(
"test", // database name
"tester", // user name
"tester", // password
SA_Oracle_Client);

printf("We are connected!\n");

// Disconnect is optional
// autodisconnect will ocur in destructor if needed
con.Disconnect();

printf("We are disconnected!\n");
}
catch(SAException &x)
{
// SAConnection::Rollback()
// can also throw an exception
// (if a network error for example),
// we will be ready
try
{
// on error rollback changes
con.Rollback();
}
catch(SAException &)
{
}
// print error message
printf("%s\n", (const char*)x.ErrText());
}

return 0;
}

What I don't understand is catch(SAException &) . Please notice that
the & is withou a name after it. So what does this (SAException &)
means?

Thanks
 
V

Victor Bazarov

hon123456 said:
Dear all,

I have following code:

[..]
try
{
// on error rollback changes
con.Rollback();
}
catch(SAException &)
{
}
[..]
What I don't understand is catch(SAException &) . Please notice that
the & is withou a name after it. So what does this (SAException &)
means?

Approximately the same as in a declaration of a function:

void foo(int&) {
std::cout << "foo\n";
}

It means that we're going to catch 'SAException' by reference, but we
don't really care about the exception object itself, so we don't provide
a way to use it. In the function example we want it to have an argument
but we don't care to use that argument, so we omit the name.

V
 
D

doublemaster007

Dear all,

           I have following code:

#include <stdio.h>  // for printf
#include <SQLAPI.h> // main SQLAPI++ header

int main(int argc, char* argv[])
{
    SAConnection con; // create connection object

    try
    {
        // connect to database
        // in this example it is Oracle,
        // but can also be Sybase, Informix, DB2
        // SQLServer, InterBase, SQLBase and ODBC
        con.Connect(
            "test",     // database name
            "tester",   // user name
            "tester",   // password
            SA_Oracle_Client);

        printf("We are connected!\n");

        // Disconnect is optional
        // autodisconnect will ocur in destructor if needed
        con.Disconnect();

        printf("We are disconnected!\n");
    }
    catch(SAException &x)
    {
        // SAConnection::Rollback()
        // can also throw an exception
        // (if a network error for example),
        // we will be ready
        try
        {
            // on error rollback changes
            con.Rollback();
        }
        catch(SAException &)
        {
        }
        // print error message
        printf("%s\n", (const char*)x.ErrText());
    }

    return 0;

}

What I don't understand is catch(SAException &) . Please notice that
the & is withou a name after it. So what does this (SAException &)
means?

Thanks

If u catch with a name and later if you donot use..u will get a
warning. This avoids warning "unused var" and also catches the
exeption obj by ref, and ignores it.
 
H

hon123456

Dear all,
I have following code:
#include <stdio.h> // for printf
#include <SQLAPI.h> // main SQLAPI++ header
int main(int argc, char* argv[])
{
SAConnection con; // create connection object
try
{
// connect to database
// in this example it is Oracle,
// but can also be Sybase, Informix, DB2
// SQLServer, InterBase, SQLBase and ODBC
con.Connect(
"test", // database name
"tester", // user name
"tester", // password
SA_Oracle_Client);
printf("We are connected!\n");
// Disconnect is optional
// autodisconnect will ocur in destructor if needed
con.Disconnect();
printf("We are disconnected!\n");
}
catch(SAException &x)
{
// SAConnection::Rollback()
// can also throw an exception
// (if a network error for example),
// we will be ready
try
{
// on error rollback changes
con.Rollback();
}
catch(SAException &)
{
}
// print error message
printf("%s\n", (const char*)x.ErrText());
}
return 0;

What I don't understand is catch(SAException &) . Please notice that
the & is withou a name after it. So what does this (SAException &)
means?

If u catch with a name and later if you donot use..u will get a
warning. This avoids warning "unused var" and also catches the
exeption obj by ref, and ignores it.- ÁôÂóQ¤Þ¥Î¤å¦r -

- Åã¥Ü³Q¤Þ¥Î¤å¦r -

Thanks very much for your help. I got it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top