Try Catch

Started by
17 comments, last by DevLiquidKnight 20 years, 8 months ago
Implementing a normal, user-initiated quit in terms of exceptions is laziness and shoddy program design. Quitting isn''t exceptional when the user requested it - exceptions should be exceptional (rare) in nature.

An abnormal event generating an exception that leads to a quit I can understand.

But don''t abuse exceptions as flow control, they aren''t used enough as is and they don''t need a bad reputation:
int main(){ try {  myHopelesslyInfiniteLoopICantStop(); } catch(const QuitException&) { } return 0;}
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Advertisement
quote:Original post by Redleaf
Not to be picky, but you should actually catch exceptions by reference. That way, a base catch statement will also catch derived exceptions.
In C++, yes, but I think langguy''s code was Java.
quote:Original post by Beer Hunter
In C++, yes, but I think langguy''s code was Java.

I would say C#

Or maybe Managed C++... I''m not sure how they treat references to __gc classes.
It''s java, because in the Java API, there is an Exception class, and if you want to create any custom exception types, you should inherit from Exception.where it is the generic catch. There is an exception class in but it isn''t as used as Java''s Exception. And if I remember correctly, you should have for C++
catch(const exception& e){....;} 
Ok the thread has gotten pedantic.

That is definitely C#.

Does Java have a MessageBox class with a static Show function like that? Of course not, in Java it''d be MessageBox.show()!
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
catch(expection) more info on what exactly the exepction part can be? i dont get it how do i iknow what i can and cannot put there? Where is it passed in? how does that work? What exactly does the catch part do like what is it catching... What will it be when its caught ect?

coder requires 0xf00d before continue().

Killer Eagle Software


[edited by - DevLiquidKnight on August 13, 2003 12:00:37 AM]
whats this do? it does nothing lol its an infinit type of thingy?

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>


int main()
{
try
{
for(int i=0; ; i++)
{
}
}
catch(int expection)
{
cout << expection << endl;
}
return 0;
}
quote:Original post by DevLiquidKnight
whats this do? it does nothing lol its an infinit type of thingy?

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>


int main()
{
try
{
for(int i=0; ; i++)
{
}
}
catch(int expection)
{
cout << expection << endl;
}
return 0;
}


It goes into an infinite loop.

Please take a look at chapter 1 in this book


Qui fut tout, et qui ne fut rien
Invader's Realm

[edited by - Invader X on August 14, 2003 1:58:50 AM]
quote:Original post by DevLiquidKnight
try...catch(int expection)
Expection handling? Hmmm... could be fun for a joke language.

This topic is closed to new replies.

Advertisement