The Artima Developer Community
Sponsored Link

Java Answers Forum
Java Error Class

5 replies on 1 page. Most recent reply: Feb 19, 2004 9:33 AM by Steven E. Newton

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
bernadette

Posts: 5
Nickname: sash6
Registered: Feb, 2004

Java Error Class Posted: Feb 17, 2004 6:04 AM
Reply to this message Reply
Advertisement
I am trying to understand the Java Error class. I have a good understanding of the Exception class, but can't find examples of code for the Error class. I've tried searching the web and also the java.sun website, but I'm not finding anything useful to help me understand this better. How would I code something like the error I get when it can't find the class?


twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Re: Java Error Class Posted: Feb 17, 2004 7:05 AM
Reply to this message Reply
See http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Error.html

If you read the documentation on the Error class, you will see that you normally won't do much with it.

bernadette

Posts: 5
Nickname: sash6
Registered: Feb, 2004

Re: Java Error Class Posted: Feb 17, 2004 7:57 AM
Reply to this message Reply
I already looked at that web page before I posted this question. That page doesn't make sense to me.

twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Re: Java Error Class Posted: Feb 17, 2004 11:20 AM
Reply to this message Reply
If an error occurs, the system has to throw something to indicate what the error is. The Error class, and its subclasses, define the objects that are thrown and what messages appear when the errors occur.

For example, if a StackOverflowError occurs, that generally means that you are using a recursive function and it recursed too deeply. There isn't any point trying to "catch" it, since it is a mistake that you want to fix before the program is considered finished. But you need the message so you know what kind of problem you need to fix.

I hope that helps a little.

tom

Gerry Giese

Posts: 18
Nickname: gerryg
Registered: Feb, 2003

Re: Java Error Class Posted: Feb 17, 2004 11:44 AM
Reply to this message Reply
The only thing you need to know is what twc sent you, and from that page, I'll quote:

"An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions."

If the guys who wrote Java think you should never try to catch a java.lang.Error, then don't! It's that simple!

I've been using Java for several years and am always looking at source code examples and miscellaneous project sources, and I don't recall anyone having used java.lang.Error in the normal course of programming. I think I saw it once or twice with some very very low-level systems/JVM programming, but that's such a specialized case that 99% of Java programmers won't EVER need to think about it.

Think about something else, like Excpetion and Throwable, and forget you ever heard about java.lang.Error.

Steven E. Newton

Posts: 137
Nickname: cm
Registered: Apr, 2003

Re: Java Error Class Posted: Feb 19, 2004 9:33 AM
Reply to this message Reply
When I was first learning Java I too was confused about the Error class and the concept of exceptions generally. I read through a number of descriptions of Error and tried various things in code to try to understand where and how Error was used, and where exceptions made sense.

I think initially the name, Error, led me to think that it was something I needed to worry about when my code wanted to indicate an error, before I understand exceptions and Throwable.

The short answer is, you'd never use Error or worry about it, unless you are coding very low-level Java vm things.

Flat View: This topic has 5 replies on 1 page
Topic: Linear Searches Previous Topic   Next Topic Topic: Why getting ClassCastException?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use