sqlHelper exception handling

G

Guest

Hi,

Calling my method below how does my page caller display the exception since
the return type is int?

int ret = 0;
string spname = "sp_UpdateAd";
try
{
//Retrieve the parameters from the cache
SqlParameter[] storedParams =
SqlHelperParameterCache.GetCachedParameterSet( connString, spname );
if( storedParams == null )
{
//Cache the parameters
SqlParameter[] paramsToStore = new SqlParameter[]
{

};
SqlHelperParameterCache.CacheParameterSet( connString, spname,
paramsToStore );
storedParams = paramsToStore;
}
ret = SqlHelper.ExecuteNonQuery( _trans, CommandType.StoredProcedure,
spname, storedParams );
}
catch( Exception ex ) { throw; }
finally{} // Do NOT dispose connection

return ret;

Thanks,
 
S

sloan

I'd read this:

http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx

since you have a "throw", the exception gets bubbled up.

the "page" you have would probably catch the exception, and then display a
message to the user.

in winforms, if you don't handle the exception in the "page", your app will
crash.

in webforms, if you don't handle the exception in the "page", your page will
show a nasty dotnet type exception message.
 
G

Guest

when I do this in my page
lblMessage.Text = a.UpdateAdStatus( ....);
it causes an cannot implicitly convert type 'int' to 'string' error, for
the method has a return type of int. Are you suggesting that I simply just do
a.UpdateAdStatus( ....);
instead?

Thanks,
--
bic


sloan said:
I'd read this:

http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx

since you have a "throw", the exception gets bubbled up.

the "page" you have would probably catch the exception, and then display a
message to the user.

in winforms, if you don't handle the exception in the "page", your app will
crash.

in webforms, if you don't handle the exception in the "page", your page will
show a nasty dotnet type exception message.


bic said:
Hi,

Calling my method below how does my page caller display the exception
since
the return type is int?

int ret = 0;
string spname = "sp_UpdateAd";
try
{
//Retrieve the parameters from the cache
SqlParameter[] storedParams =
SqlHelperParameterCache.GetCachedParameterSet( connString, spname );
if( storedParams == null )
{
//Cache the parameters
SqlParameter[] paramsToStore = new SqlParameter[]
{

};
SqlHelperParameterCache.CacheParameterSet( connString, spname,
paramsToStore );
storedParams = paramsToStore;
}
ret = SqlHelper.ExecuteNonQuery( _trans, CommandType.StoredProcedure,
spname, storedParams );
}
catch( Exception ex ) { throw; }
finally{} // Do NOT dispose connection

return ret;

Thanks,
 
S

sloan

dim x as string = Convert.ToString ( a.UpdateAdStatus () )

lblMessage.Text = x

........

You do explicit converts/casts in order to avoid confusion.


Old VB6 code

dim s as string
s = 6 + 2

do you want 8 or "62"

...

In DotNet, you say what you want

dim s as string

s = Convert.ToString(6) + Convert.ToString(2)
's would be 62

s = Convert.ToString ( 6+2 )
's would be 8

.............

bic said:
when I do this in my page
lblMessage.Text = a.UpdateAdStatus( ....);
it causes an cannot implicitly convert type 'int' to 'string' error, for
the method has a return type of int. Are you suggesting that I simply
just do
a.UpdateAdStatus( ....);
instead?

Thanks,
--
bic


sloan said:
I'd read this:

http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx

since you have a "throw", the exception gets bubbled up.

the "page" you have would probably catch the exception, and then display
a
message to the user.

in winforms, if you don't handle the exception in the "page", your app
will
crash.

in webforms, if you don't handle the exception in the "page", your page
will
show a nasty dotnet type exception message.


bic said:
Hi,

Calling my method below how does my page caller display the exception
since
the return type is int?

int ret = 0;
string spname = "sp_UpdateAd";
try
{
//Retrieve the parameters from the cache
SqlParameter[] storedParams =
SqlHelperParameterCache.GetCachedParameterSet( connString, spname );
if( storedParams == null )
{
//Cache the parameters
SqlParameter[] paramsToStore = new SqlParameter[]
{

};
SqlHelperParameterCache.CacheParameterSet( connString, spname,
paramsToStore );
storedParams = paramsToStore;
}
ret = SqlHelper.ExecuteNonQuery( _trans, CommandType.StoredProcedure,
spname, storedParams );
}
catch( Exception ex ) { throw; }
finally{} // Do NOT dispose connection

return ret;

Thanks,
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top