PC Review


Reply
Thread Tools Rate Thread

can't find error in code

 
 
=?Utf-8?B?TGVl?=
Guest
Posts: n/a
 
      18th Feb 2004
The following code generates the error "...not all code paths return a value" but I can't find the problem. I have tried putting "return;" or "return 0;" just after the close of the "if" statement with no luc

protected void sGetError(SqlException oException, SqlConnection db

int i
sError = ""
if (db != null)

for (i = 0; i < oException.Errors.Count - 1; i++

sError = sError + oException.Errors[i].ToString() + "/n"




 
Reply With Quote
 
 
 
 
William Ryan eMVP
Guest
Posts: n/a
 
      18th Feb 2004
Lee:

It's running fine for me, the only thing I changed was the second line to
string sError = string.Empty;

(b/c sError is declared outside of this function).
"Lee" <(E-Mail Removed)> wrote in message
news:E772AE06-CD44-4790-A173-(E-Mail Removed)...
> The following code generates the error "...not all code paths return a

value" but I can't find the problem. I have tried putting "return;" or
"return 0;" just after the close of the "if" statement with no luck
>
> protected void sGetError(SqlException oException, SqlConnection db)
> {
> int i;
> sError = "";
> if (db != null)
> {
> for (i = 0; i < oException.Errors.Count - 1; i++)
> {
> sError = sError + oException.Errors[i].ToString() + "/n";
> }
> }
> }
>



 
Reply With Quote
 
Eric Cadwell
Guest
Posts: n/a
 
      18th Feb 2004
You didn't declare a type for sError. This method has no return!

protected void sGetError(SqlException oException, SqlConnection db)
{
int i;
string sError = "";
if (db != null)
{
for (i = 0; i < oException.Errors.Count - 1; i++)
{
sError = sError + oException.Errors[i].ToString() + "/n";
}
}
}


HTH;
Eric Cadwell
http://www.origincontrols.com


 
Reply With Quote
 
Eric Cadwell
Guest
Posts: n/a
 
      18th Feb 2004
Wierd, maybe the signature should read:

protected string sGetError(SqlException oException, SqlConnection db)
{
string sError = string.Empty;
... //build the string

return sError;
}

instead of declaring sError outside the function.

-Eric


 
Reply With Quote
 
William Ryan eMVP
Guest
Posts: n/a
 
      18th Feb 2004
Eric:

I'm not following you. I took Lee's code and pasted it into a C# project
and it compiled except for that fact that sError wasn't declared. Once it
was, it compiled fine. However, the signature is void, hence it has no
return type so I'm not sure I understand your point.

Bill
"Eric Cadwell" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You didn't declare a type for sError. This method has no return!
>
> protected void sGetError(SqlException oException, SqlConnection db)
> {
> int i;
> string sError = "";
> if (db != null)
> {
> for (i = 0; i < oException.Errors.Count - 1; i++)
> {
> sError = sError + oException.Errors[i].ToString() + "/n";
> }
> }
> }
>
>
> HTH;
> Eric Cadwell
> http://www.origincontrols.com
>
>



 
Reply With Quote
 
Eric Cadwell
Guest
Posts: n/a
 
      19th Feb 2004
Yes, I found the same thing, but it never occurred to me that he had
declared sError outside the function (as you noted).
I'm just confused how he got that error message from a void function?

-Eric


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Code, but I Can't Find It! croy Microsoft Access Form Coding 4 1st Oct 2007 08:57 PM
Find the Error in my Code Please =?Utf-8?B?Q2hyaXN0aW5l?= Microsoft Excel Programming 4 15th May 2006 11:47 AM
'Circular reference' error but can't find such an error in the code. Richard Lewis Haggard Microsoft C# .NET 10 2nd May 2006 03:45 PM
Cannot Find Error Code! Please Help Here =?Utf-8?B?Um9iZXJ0?= Windows XP Music 1 16th Jan 2006 07:40 PM
I cannot find a setup error code in the KB (error code is 4) Ed Becker Microsoft Windows 2000 Setup 1 29th Oct 2003 12:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:37 PM.