471,338 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

try-catch, go to catch by statement

try
{
if(i==3)
goto catch;

Console.WriteLine(i);

}
catch
{
Console.WriteLine("i = 3");
}
any statement can do the below job?
goto catch;
or i must write a dirty statement like open a non exceed file?

Thanks
Aug 26 '08 #1
5 5200
throw an exception :-)

Aug 26 '08 #2
On 26 Aug., 12:02, "macneed" <macn...@yahoo.com.hkwrote:
* * * * * * try
* * * * * * {
* * * * * * * * if(i==3)
* * * * * * * * * * goto catch;

* * * * * * * * Console.WriteLine(i);

* * * * * * }
* * * * * * catch
* * * * * * {
* * * * * * * * Console.WriteLine("i = 3");
* * * * * * }

any statement can do the below job?
goto catch;
or i must write a dirty statement like open a non exceed file?
Check out "throw"

Aug 26 '08 #3
macneed was thinking very hard :
try
{
if(i==3)
goto catch;

Console.WriteLine(i);

}
catch
{
Console.WriteLine("i = 3");
}
any statement can do the below job?
goto catch;
or i must write a dirty statement like open a non exceed file?

Thanks
you could throw an exception yourself:
throw new Exception("i == 3");

There is no need to do something illegal just to get an exception to be
thrown.
But I don't think you should use exceptions for this. Why not just a
regular if/else?

Hans Kesting
Aug 26 '08 #4
Oh man. Please don't think in "goto" terms, let alone try to type them.
.......

http://blogs.msdn.com/kcwalina/archi...16/396787.aspx
(A great post by Krzysztof Cwalina on exceptional handling)


"macneed" <ma*****@yahoo.com.hkwrote in message
news:48********@127.0.0.1...
try
{
if(i==3)
goto catch;

Console.WriteLine(i);

}
catch
{
Console.WriteLine("i = 3");
}
any statement can do the below job?
goto catch;
or i must write a dirty statement like open a non exceed file?

Thanks

Aug 26 '08 #5
On Aug 26, 2:02*pm, "macneed" <macn...@yahoo.com.hkwrote:
* * * * * * try
* * * * * * {
* * * * * * * * if(i==3)
* * * * * * * * * * goto catch;

* * * * * * * * Console.WriteLine(i);

* * * * * * }
* * * * * * catch
* * * * * * {
* * * * * * * * Console.WriteLine("i = 3");
* * * * * * }

any statement can do the below job?
bool failed = false;
try
{
if (i == 3)
{
failed = true;
}
else
{
Console.WriteLine(i);
}
}
catch
{
failed = true;
}
if (failed)
{
Console.WriteLine("i = 3");
}
Aug 26 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

39 posts views Thread by Erlend Fuglum | last post: by
4 posts views Thread by Brian Alexander | last post: by
13 posts views Thread by KefX | last post: by
7 posts views Thread by Robert Brewer | last post: by
9 posts views Thread by David Stockwell | last post: by
26 posts views Thread by djw | last post: by
40 posts views Thread by Steve Juranich | last post: by
2 posts views Thread by Abubakar | last post: by
reply views Thread by rosydwin | last post: by

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.