Welcome Guest Search | Active Topics | Members | Log In | Register

Re: sqlHelper exception handling Options · View
sloan
Posted: Wednesday, October 03, 2007 6:25:59 PM


Rank: Guest
Groups: Guest

Joined: 9/17/2007
Posts: 11,670
Points: -1,200
Date parsed: 03/10/2007 18:25:59
Date: Wed, 3 Oct 2007 22:25:59 -0400


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" <bic@discussions.microsoft.com> wrote in message
news:890C1EAD-F120-42F6-94E9-7443D53A6C4B@microsoft.com...
> 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,
>
> --
> bic


sloan
Posted: Sunday, October 07, 2007 8:12:38 PM


Rank: Guest
Groups: Guest

Joined: 9/17/2007
Posts: 11,670
Points: -1,200
Date parsed: 07/10/2007 20:12:38
Date: Mon, 8 Oct 2007 00:12:38 -0400


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" <bic@discussions.microsoft.com> wrote in message
news:08AC8570-2E91-49A2-8D81-70B03F64D52A@microsoft.com...
> 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" wrote:
>
>>
>> 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" <bic@discussions.microsoft.com> wrote in message
>> news:890C1EAD-F120-42F6-94E9-7443D53A6C4B@microsoft.com...
>> > 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,
>> >
>> > --
>> > bic
>>
>>
>>


Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.1 (NET v2.0) - 9/10/2007
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.
This page was generated in 0.043 seconds.