4 Types of exception and the code to handle them

Dear all,
I would like to know wheter runtime exception, errors exception, unchecked exception and checked exception are classified as the 4 types of exception.
What are the java coding of them? please help.

There are two main families of exception in Java: checked and unchecked.
The base class for all exceptions is Throwable. Java provides Exception and Error that extend Throwable. RuntimeException (and many others) extend Exception.
RuntimeException and its descendants, and Error and its descendants, are called unchecked exceptions. Everything else is a checked exception.
If your method, or any method it calls, can throw a checked exception, then your method must either catch that exception, or declare that your method throws that exception. This way, when I call your method, I know at compile time what can possibly go wrong and I can decide whether to handle it or just bubble it up to my caller. Catching a given exception also catches all that exception's descendants. Declaring that you throw a given exception means that you might throw that exception or any of its descendants.
Unchecked exceptions (RuntimeException, Error, and their descendants) are not subject to those restrictions. Any method can throw any unchecked exception at any time without declaring it. This is because unchecked exceptions are either the sign of a coding error (RuntimeException), which is totally preventable and should be fixed rather than handled by the code that encounters it, or a problem in the VM, which in general can not be predicted or handled.
http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html

Similar Messages

  • Besides throwing exceptions and the "return;" statement

    Besides throwing exceptions and the "*return*" statement, what else clauses could complete a code block abruptly?
    Originally I thought System.exit() should be one of that kind, and I was totally puzzled by the fact that finally clause dose not work with System.exit(). But after a few thoughts, it becomes clear to me that System.exit() dose not even complete a code block, let alone completing a code block abruptly. So is there other logic that could make a code block complete abruptly?
    My question originates from paragraphs in <Thinking in JAVA>, which claim that, I quote,
    "Unfortuantely, there's a flaw in Java's exception implementation. Although exceptions are an indication of a crisis in your program and should never be ignored, it's possible for an exception to simply be lost. This happens with a particular configuration using a finally clause"..."This is a rather serious pitfall, since it means that an exception can be completely lost, and in a far more subtle and difficult -to-detect fashion..."..."Perhaps a future version of Java will repair this problem"...
    After check with JLS, it seams that it is legitimate to ignore the reason for the abrupt completion of the try block, if the corresponding finally block completes abruptly. I think whether this is a "pitfall, flaw" or not depends on how deeply we language users understand the purpose of the finally clause and it is better for me to know all the possible reasons for a code block to complete abruptly.
    So, besides throwing exceptions and the "*return*" statement, what else clauses could complete a code block abruptly?

    warnerja wrote:
    Case 1: Normal flow (no exception is about to be bubbled to the caller before getting to the finally block) - I'd say we want an exception back due to the failure to close the stream.
    Case 2: The finally block was entered through an exception about to be bubbled to the caller - the caller can only get one or the other exception back, either the original exception or the one indicating the failure to close the stream. The finally block has no access to the pending exception however and is unaware of whether there is an exception pending or not. All it knows is an exception occurred during the execution of the finally block, and should throw that or wrap it in another exception - same handling as in Case 1.
    try {
      write();
      flush();
    finally {
      try {
        close();
      catch (...) {
        log();
    }The flush() at the end of try seems kind of redundant, since close() calls flush() anyway. The benefit is that the try statement completion matches the try block ("real work") completion.
    If we get to the end of the try block with no exception, then write() and flush() have succeeded and the data is where it needs to be. All that's left is to release the I/O resource, which will always be done in finally.
    If there's an exception in the try block, it is propagated out, so we know of any failure that occurred doing the "real work." The I/O resource is still released in finally.
    Regardless of how the try block completed, releasing the resource does not affect how the try statement completes, and hence does not supersede how our "real work" completes, which is all we care about. We still log any close() errors for later investigation. What matters to our program is whether all the data was written, and the completion of write() and flush() tells us that.

  • The code you entered is invalid. Please try again.   I bought the card at my school book store today and the code is not activating.  Paid almost $250 for this I need this to activate.

       I bought the card at my school book store today and the code is not activating.  Paid almost $250 for this I need this to activate.  It is for Adobe Creative Cloud 12- month prepaid membership.  The card says it is windows and mac compatible and I am using Windows.  It is Student and Teacher Edition and I am a student.  I also have light room 5 which was purchased the same way and it works. 

    Hi johnashton07,
    We have noticed that some of our customer's tends to miss-type the code as there is a bit of confusion around the font of the redemption code.
    Common miss-type issues  found are mentioned below.
    Zero(0)  -  letter "O" as in Oscar.
    Five (5) - Letter "S" as in Sam.
    Two (2)  - Letter "Z" as in Zolo.
    Kindly try replacing these characters and please revert to the PM.
    Thanks,
    Atul Saini

  • I recently subscribed to Adobe ExportPDF and tried to convert a PDF file to MS Word.  So far,  after many tries,  I get soe type of error and the conversion fails.  Please advise?

    I recently subscribed to Adobe ExportPDF and tried to convert a PDF file to MS Word.  So far,  after many tries,  I get soe type of error and the conversion fails.  Please advise?

    Hi there,
    It sounds like there may be an issue with the quality of the PDF. Not all PDFs are created equal, and especially those created from scanned documents can be problematic if the scan quality isn't the best. Is there a dark background on the PDF, or stray marks or smudges?
    You can try converting with OCR disabled at outlined in this document: How to disable Optical Character Recognition (O... | Adobe Community. But, while that's a good test to find out where the problem lies, you'll end up with a Word document that isn't editable, so it's not an optimal solution.
    Please let us know how it goes.
    Best,
    Sara

  • I want to see in the tv what i am seeing in my ipad, but i followed all the steps and the code doesnt appears in the tv

    I have a apple tv and i wnat to use the airplay. I followed all the steps and the code does not appear in the tv

    Hello maicamtz,
    The following article provides some useful troubleshooting steps that can hlep get AirPlay working.
    iOS: Troubleshooting AirPlay and AirPlay Mirroring
    http://support.apple.com/kb/TS4215
    Cheers,
    Allen

  • I have redeemed my code and downloaded the Mountain Lion overnight. Now I am unable to find the download and unable to install it. And the code says that its already redeemed. What can I do? Please help.

    I have redeemed my code to download the Mountain Lion. I left it for download overnight. Now I am unable to find the download and its not installed. And the code says that its already redeemed so I cannot download the Mountain Lion again. Please help.

    Look in your Applications folder.

  • HT201209 I have a Amex Gift card and input everything and the code does not work

    I have a Amex gift card and input everything and the code does not work

    http://www.apple.com/legal/itunes/us/terms.html  - Does an Amex gift card count as a credit card?  For example, it doesn't say debit cards are accepted.  I believe one of hte differences between American Express and other cards is AmEx is not a credit card.

  • I have a gift card and the code is scratched

    i have a gift card and the code is scratched

    You will need to try contacting iTunes Support (you will probably need to give them images of the front and back of the card, and possibly its receipt) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then iTunes Cards And Codes

  • I buy a card and the code apears as invalid.what can i do?

    I buy a gift card and the code apears invalid, what can i do?

    See this:  iTunes Store:  Invalid, Inactive, or Illegible codes, http://support.apple.com/kb/TS1292

  • How do I get my bookmarks to display again in a column on the left of my screen, just as it always has and the way I like them. I do not want to use full screen display without the bookmarks showing.

    I have a full screen and cannot see my bookmarks.
    How do I get my bookmarks to display again in a column on the left of my screen, just as it always has and the way I like them. I do not want to use full screen display without the bookmarks showing.

    View > Sidebar > Bookmarks (Ctrl+B)
    Press F10 or tap the Alt key to bring up the "Menu Bar" temporarily.

  • TS3276 When I add a name to the "To" box or CC/BCC box and then change my mind about sending an email to them, Mail is ignoring the instruction to "remove" so that once the email has been sent, their name is still included and the email goes to them anywa

    Can anyone help?  When sending an email and I add a name to the "To" box or CC/BCC box which I later decided I don't want to include, Mail ignores the instruction to "remove" that name so that once the email has been sent, the name is still included and the email goes to them anyway.  Pretty frustrating and I don't understand why this is happening. 

    You would really have to ask the app developer if there is a way to export the data.
    As for adding a printer, you would need to purchase an AirPrint compatible printer and connect it to your wireless network.
    By the way, your holiday letter/rant/Idon't even know what to call it... is completely inappropriate for these forums.

  • Program code and transaction code  for handling unit detail

    Developed a SAP Script for the Handling unit details. Handling unit details is a document which has the details of materials, packaging materials and the level of packing. This Handling Units details will be issued to the customer at the time of delivery.

    Hi,
    Goto NACE transaction code , there you select the application area then  it will give you the list  of output types then select specific output click processing routines then you will see the program name and  script used.
    Or esle goto SPRO tcode then you can find the functional tab there also you can get the details.
    Thanks,
    Aditya

  • I am updating content in an old site and am using an old extension to close a child page.  It has worked fine up until I started using CS6.  The code for this is in a template I am using and the code has not changed.

    So the site is www.fulcrumcwi.com and the page URL is: FulcrumCWI Rebecca Morgan Operations Strategy Consulting Newsletters.
    if you choose the first HTML link to the current newsletter when you try to use the close buttons neither of them work.  Yet if you go down to the issue from January, and go to the HTML version, it works just fine.  This is the code that the extension puts in:
    <form>
              <input name="Close" onclick="self.close();return false" type="button" value="Close" />
            </form>
    I haven't changed it in any way.  The only change is that I'm using Dreamweaver CS6 to make these changes.  Anyone have a fix for me?
    As always, thanks in advance.  (and yes, I know this site needs major updating)
    GraphicEdge

    Boy, that didn't really come out very well.
    On the archive_newsletters.html page, the "HTML" links are supposed to have target="_blank" in them...
    <a href="newsletters_html/2014_03.html" target="_blank">HTML</a>
    so a new tab is opened with the info. That new tab is then closed by the this.close() javascript.
    On the newsletters that don't close correctly, there is no target="_blank" to open them in a new window initially, so they can't close with that method.

  • New form and the code for it..!!!???

    I have created an outlay in forms6i....with the following fields.
    Site name,site id, stc no,MC,district,region
    in this form i have variouss check boxes which are around 15 i.eSDH-MX,DW-DM,SYNC
    and i have got four buttons in this forms like first record,previous record,next record,last record......
    So,when i click first record i want the first record to be displayed, and the same for other 3 buttons also....
    can any1 help me out how shud i proceed with this......i mean what code shud u write for this 4 buttons to work...!!!!

    It seems like this is your first fmb.. :)
    After Creating the datablock for the required table,
    take the property pallete and ensure the fol. properties
    Database Data block: Yes
    Query Allowed : Yes
    Query Data Source Type : Table
    Query Data Source Name : List_of_sites
    Insert Allowed : Yes
    Update Allowed : Yes
    DML Data Target Type : Table
    If all the above properties are set, you will be abe to do DML operations ..
    I hope after saving , you might have got a message in the status bar
    saying Transaction complete: 2 records applied and saved.

  • TS1292 I got an iTunes gift card for $15.00 and the code sticker ripped so now I can't make it out. So what do do?

    I got an iTunes gift card for Xmas and when scratching code it ripped so now you can't make out part of it what do I do

    Click here and request assistance. Include as much of the code as you can.
    (73379)

Maybe you are looking for

  • New Tax code Creation for CST(Condition type

    Hi Friends, I am facing an issue during creation of new Tax-code for CST; condition type JIN1. After defining the tax percentage; system is picking an automatic G/L account, which is a grey field and can't be editable. We need to change G/L account a

  • Error value after modifying the contract

    Hi Guys, I need help in getting the correct values of u2018Released valueu2019 field of Contract. I have written code in u2018ZV_USEREXIT_SAVE_DOCUMENTu2019.  The following code is updating incorrectly on the screen for all line items with the last v

  • How to start with JMS?

    Hi All I am new to JMS, i know about java basic stuff.... what do i need to start with JMS? i mean.. what software/applications/servers? I have J2SDK 1.4.2_03, what concepts should i know as pre-requisites... ? Thanx..

  • [T440p] TrackPoint buttons not working

    Hi, I have a weird problem with my T440p's TrackPoint (running Windows 7 Pro, x86) using out-of-the-box settings. Basically, it seems that its buttons do not work at all - the designated upper regions of the TouchPad (which should supposedly function

  • Issue with Logitech Bluetooth mouse

    Hi everyone! I have some problems in correctly configuring my Logitech v270 bluetooth mouse. I followed all the steps in http://wiki.archlinux.org/index.php/Bluetooth_Mouse, but I still can't connect automatically at startup. Each time I boot my lapt