Re: Simple throw question...
Here is a good explanation about it.
As far as the VC++ help, you can also use msdn.
Re: Simple throw question...
Did I post to the wrong group... This is C# isn't it?
Re: Simple throw question...
Quote:
Originally Posted by JustSomeGuy
how do I code the try catch for something like..
Code:
if (x < 0)
throw("Parameter out of bounds.");
Code:
try
{
if (x < 0)
throw new Exception("Parameter out of bounds.");
}
catch
{
Console.WriteLine("");
}
Re: Simple throw question...
Except throw an 'ArgumentOutOfRange' exception as opposed to an 'Exception'.
i.e.
throw new ArgumentOutOfRangeException ("x");
Re: Simple throw question...
Quote:
Originally Posted by Mutant_Fruit
Except throw an 'ArgumentOutOfRange' exception as opposed to an 'Exception'.
i.e.
throw new ArgumentOutOfRangeException ("x");
Be nice :)
... You're right though
Re: Simple throw question...
Re: Simple throw question...
Quote:
Originally Posted by JustSomeGuy
Did I post to the wrong group... This is C# isn't it?
Woops, sorry my bet.
Re: Simple throw question...
Quote:
Originally Posted by opedog
Code:
try
{
if (x < 0)
throw new Exception("Parameter out of bounds.");
}
catch
{
Console.WriteLine("");
}
True enough, that ParameterOutOfBounds is probably the write exception to throw... However, in you example, how would you get the Message that was thrown with the execption... Is it in the Exception class?
Thanks!
Re: Simple throw question...
Quote:
Originally Posted by JustSomeGuy
True enough, that ParameterOutOfBounds is probably the write exception to throw... However, in you example, how would you get the Message that was thrown with the execption... Is it in the Exception class?
Thanks!
Replace the catch bit of my example with this:
Code:
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
This is also permissable:
Code:
catch (ArgumentOutOfBoundsException aoobex)
{
Console.WriteLine(aoobex.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}