All the googling I've done seems focused on "catching" errors. I want to be able to raise my own if certain conditions are met. I tried using the Error() class and its subclasses but Eclipse doesn't recognize them.
This is what I want to do:
if(some_condition) {
foobar();
}
else {
// raise an error
}
Stupid question, I know, but I've done my googling and I figure someone out there would be able to help me.
Thanks in advance!
Thanks everyone! If you are reading this in the future, here's the skinny:
Errors in Java refer to problems that you should NOT try to catch
Exceptions refer to errors that you may want to catch.
Here's my "fixed" code:
if(some_condition) {
foobar();
}
else {
throw new RuntimeError("Bad.");
}
I used RuntimeError()
because, as one answer pointed out, I don't have to declare that I'm throwing an error beforehand, and since I'm relying on a condition, that's very useful.
Thanks all!