473,320 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do you get around this?

Sorry for the stupid question, but I've been there and done that. Just
that just now I have forgotten it for the moment. It happens when
you're in a totally different rut of thought. Bail me out here.

Just to quote an example:

static void Main(string[] args)
{
Console.WriteLine((new Class1()).SomeMethod((Object)19));
}

public int SomeMethod(System.Object obj)
{
if (obj == null)
throw new System.Exception("The argument is null.");

if ((int)obj >= 10)
return (int)obj;
}
Error: Class1.cs(13): 'Exception.Class1.SomeMethod(object)': not all
code paths return a value

How do you get out of this?

Jul 26 '06 #1
6 1159
Hi Walter,

public int SomeMethod(System.Object obj)
{
//...
if ((int)obj >= 10)
return (int)obj;
}

What does it return if (int)obj is NOT greater than 10?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Sequence, Selection, Iteration.
"Water Cooler v2" <wt*****@yahoo.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Sorry for the stupid question, but I've been there and done that. Just
that just now I have forgotten it for the moment. It happens when
you're in a totally different rut of thought. Bail me out here.

Just to quote an example:

static void Main(string[] args)
{
Console.WriteLine((new Class1()).SomeMethod((Object)19));
}

public int SomeMethod(System.Object obj)
{
if (obj == null)
throw new System.Exception("The argument is null.");

if ((int)obj >= 10)
return (int)obj;
}
Error: Class1.cs(13): 'Exception.Class1.SomeMethod(object)': not all
code paths return a value

How do you get out of this?

Jul 26 '06 #2
Is it because you're not returning a value if the parameter passed is
null? (I know you're throwing an exception but the warning points to
the fact that this particular code path doesn't return anything.

HTH
Martin
Water Cooler v2 wrote:
Sorry for the stupid question, but I've been there and done that. Just
that just now I have forgotten it for the moment. It happens when
you're in a totally different rut of thought. Bail me out here.

Just to quote an example:

static void Main(string[] args)
{
Console.WriteLine((new Class1()).SomeMethod((Object)19));
}

public int SomeMethod(System.Object obj)
{
if (obj == null)
throw new System.Exception("The argument is null.");

if ((int)obj >= 10)
return (int)obj;
}
Error: Class1.cs(13): 'Exception.Class1.SomeMethod(object)': not all
code paths return a value

How do you get out of this?
Jul 26 '06 #3
Water Cooler v2 wrote:
Sorry for the stupid question, but I've been there and done that. Just
that just now I have forgotten it for the moment. It happens when
you're in a totally different rut of thought. Bail me out here.

Just to quote an example:

static void Main(string[] args)
{
Console.WriteLine((new Class1()).SomeMethod((Object)19));
}

public int SomeMethod(System.Object obj)
{
if (obj == null)
throw new System.Exception("The argument is null.");

if ((int)obj >= 10)
return (int)obj;
What if obj is < 10? You still need to return something.
}
Error: Class1.cs(13): 'Exception.Class1.SomeMethod(object)': not all
code paths return a value

How do you get out of this?
Return something from all paths, just like the error says.

-cd
Jul 26 '06 #4
The question should be... what does SomeMethod return if "obj < 10". You
have defined the function as returning an int, so it must return an int. As
coded, if "obj>=10" then you return a value. If this test fails, you do not
return anything.

Steve
"Water Cooler v2" <wt*****@yahoo.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Sorry for the stupid question, but I've been there and done that. Just
that just now I have forgotten it for the moment. It happens when
you're in a totally different rut of thought. Bail me out here.

Just to quote an example:

static void Main(string[] args)
{
Console.WriteLine((new Class1()).SomeMethod((Object)19));
}

public int SomeMethod(System.Object obj)
{
if (obj == null)
throw new System.Exception("The argument is null.");

if ((int)obj >= 10)
return (int)obj;
}
Error: Class1.cs(13): 'Exception.Class1.SomeMethod(object)': not all
code paths return a value

How do you get out of this?

Jul 26 '06 #5
Pritcham wrote:
Is it because you're not returning a value if the parameter passed is
null? (I know you're throwing an exception but the warning points to
the fact that this particular code path doesn't return anything.
No, it's not the null code path that's causing the problem - it's the
non-null, less than 10 code path. The compiler is perfectly happy for
something to guarantee it will throw an exception instead of returning
a value.

Jon

Jul 26 '06 #6
"Water Cooler v2" wrote:
Sorry for the stupid question, but I've been there and done that. Just
that just now I have forgotten it for the moment. It happens when
you're in a totally different rut of thought. Bail me out here.
Just make sure all paths return a value. In your example:

public int SomeMethod(System.Object obj)
{
int i = 0;
if (obj == null)
throw new System.Exception("The argument is null.");
if ((int)obj >= 10)
i = (int)obj;
return i;
}

--
Timm Martin
Mini-Tools
..NET Components and Windows Software
http://www.mini-tools.com

>
Just to quote an example:

static void Main(string[] args)
{
Console.WriteLine((new Class1()).SomeMethod((Object)19));
}

public int SomeMethod(System.Object obj)
{
if (obj == null)
throw new System.Exception("The argument is null.");

if ((int)obj >= 10)
return (int)obj;
}
Error: Class1.cs(13): 'Exception.Class1.SomeMethod(object)': not all
code paths return a value

How do you get out of this?

Jul 27 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andy Jefferies | last post by:
I'm having problems stripping out the whitespace at the beginning of a particular element. In the XML snippet I've highlighted tabs and returns as ^I and ^M respectively: <para> ^I ^I ...
23
by: Bob Bedford | last post by:
I've a table. The table must not have any border. The TR (every line) must have a border, but not the lines between cells. The TR.pages must have no border. so .mytable{border:0px;} ...
0
by: Al Dente | last post by:
Round round get around I get around Yeah Get around round round I get around I get around Get around round round I get around From town to town Get around round round I get around I'm a real...
14
by: Eric Lindsay | last post by:
I've seen a page using display, and especially display table that did some neat things with boxes, but basically it only worked with Mozilla browsers. Fell over fairly badly with Opera and Safari...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
3
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing...
8
by: UJ | last post by:
I have a table with multiple cells and I want to draw a box around the entire table but not around the individual cells. How do I do that? TIA - Jeff.
1
by: maya | last post by:
hi, I have to do a page where there's a paragraph with an img on top left and the text in paragr has to wrap around the image.. pls see screen-shot here......
6
by: natkw1 | last post by:
Hi all, I'm new to C and kind of confused on this. I've had a look around this group for suggestions but still not sure why the warning is occurring. What I've done is this <code snip> void...
14
by: greentiger1 | last post by:
I'm moderately experienced in CSS. I am currently working on a new version of my site, built from the ground up, but the dynamic portion, loaded with a PHP include into the 'chest' DIV is being...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.