Checked and unchecked exceptions - when to use which ?

Hi,
Example:
public void go(String[] args) {
   if(args.length==0)
      throw new //   <= what type of an exception should come here ?
}Is there a good explanation when to use which one ? I know that generally
unchecked exception are the exceptions associated with errors in the logic
of your applications and checked are those which you can not determine
(like files, networks problems ....).
Thanks,
Adrian

There is no, "I think it is better to us a type-XXX exception here because of conditions 1, 2, and 3" scenario.
Checked exceptions are of type java.lang.Exception and must be handled in one of two ways- try/catch constructs or having the method state it throws the checked exception.
Unchecked exceptions are of type java.lang.Error or java.lang.RuntimeException. If the problem is an Error, something very bad has occurred like running out of memory. If it is a RuntimeError, then it probably came from a program bug. In both cases, there is no way for you to know when they will arise. Therefore the compiler does not force you to handle these unusual circumstances.
If you think of piece of code may throw an error like an I/O operation, and you do not have code to handle that possibility, the compiler will let you know. After you have been programming long enough, you'll begin to know when you need try/catch constructs without Mr. Compiler yelling at you. ;-)
Edited by: filestream on Sep 14, 2007 5:37 PM

Similar Messages

  • Checked and unchecked exception

    what is the differance between the checked and unchecked ecxeption.

    Any exception deriving from RuntimeException (which is a sublclass of Exception) is unchecked.
    All other exceptions derived from Exception class are checked ones.
    Checked exceptions are indicated by the throws clause. But unchecked exceptions are not.
    An example of unchecked exception is NullPointerException.
    A programmer should not write code to catch unchecked exceptions.

  • Difference between EAI and SOA? when to use which one?

    Hi,
    Please share this information, What IS EAI and What is SOA? why they came and what its use, and when we have to use which of these?
    Thanks.

    EAI is the mother of all the integrations. EAI acts as a connector and can integrate at large scale however SOA is another integration technique which is used for small scale integration. SOA is an approach to have software resources in an enterprise available and discoverable on network as well defined services. Each service would achieve a predefined business objective and perform discrete units of work. The services are independent and do not depend on the context or state of the other services. They work within distributed systems architecture.
    Regards,
    Anuj

  • Checked and unchecked Exceptions

    I'm novice(new to java) could anyone please explain it in best way.
    Thanks in advance

    http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
    If you're new to Java, start with reading the tutorials (or a Java book):
    http://java.sun.com/docs/books/tutorial/
    -Puce

  • I have an apple ID which I use to sign into icloud for my iPad and iPhone.But when I use the same ID for setting up iCloud on my Macbook it says INCORRECT ID or password, try again. I tried changing my passwords but it does not work for the macbook.

    I have an apple ID which I use to sign into icloud for my iPad and iPhone.But when I use the same ID for setting up iCloud on my Macbook it says INCORRECT ID or password, try again. I tried changing my passwords several times but it does not work for the macbook.

    You will have to provide the correct password to delete the existing account, if you have tried but are not getting the password reset email, contact Apple for assistance by going to https://expresslane.apple.com, then click More Products and Services>Apple ID>Other Apple ID Topics>Lost or forgotten Apple ID password.

  • What is ESB and OSB? why OSB when ESB avail? when to use which of these?

    Hi,
    What is ESB and OSB? why OSB when ESB avail? when to use which of these? Which is recommendabale?

    ESB (Enterprise Serice Bus) is backbone of SOA. OSB (Oracle Service Bus) is an ESB product. Before the acquisition of BEA, Oracle was using OESB (Oracle Enterprise Service Bus) as a service bus but after that Oracle renamed ALSB (Aqualogic Service Bus) to OSB. Below SOD should help you out in understanding -
    http://www.oracle.com/technology/products/integration/service-bus/docs/Oracle-Service-Bus-SOD.pdf
    Regards,
    Anuj

  • Error : Old and new exceptions cannot be used at the same time.

    HI ALL,
    i build a new exception class with message class and i want to replace the
    old exception that i had in the method ,what i did is delete the exception from the method
    signature and add the exception class .
    the problem is that when i try to activate the method i get error :
    Old and new exceptions cannot be used at the same time.
    CALL FUNCTION 'CALCULATE_HASH_FOR_CHAR'
          EXPORTING
            alg            = 'MD5'
            data           = iv_iss
          IMPORTING
            hash           = lv_issu
          EXCEPTIONS
            unknown_alg    = 1
            param_error    = 2
            internal_error = 3
            OTHERS         = 4.
        IF sy-subrc <> 0.
          RAISE EXCEPTION TYPE cx_user_mng EXPORTING
          textid = cx_user_mng=>wrong_isrs.
        ENDIF.
    I want to use the new exception class ,
    how can i avoid this error ?
    Best Regards
    Edited by: Joy Stpr on Jul 22, 2009 2:56 PM
    Edited by: Joy Stpr on Jul 22, 2009 3:16 PM

    Hi Joy,
    Check this link.
    [Old and New Exceptions Cannot be used at same time|Urgent problem, give me a hand;
    Old and new exceptions cannot be used the same time, what does this mean???
    Regards,
    Lakshman.

  • Checked or Unchecked Exceptions

    I've had people explain the differences of checked exceptions and unchecked exceptions but I just can't seem to get it into my head. Can anyone help explain what the differences are?

    Exceptions: Most programs throw and catch objects that derive from the Exception class. Exceptions indicate
    that a problem occurred but that the problem is not a serious JVM problem. An Exception class has many
    subclasses. These descendants indicate various types of exceptions that can occur. For example,
    NegativeArraySizeException indicates that a program attempted to create an array with a negative size. One
    exception subclass has special meaning in the Java language: RuntimeException. All the exceptions except
    RuntimeException are compiler checked exceptions. If a method is capable of throwing a checked exception it
    must declare it in its method header or handle it in a try/catch block. Failure to do so raises a compiler error. So
    checked exceptions can, at compile time, greatly reduce the occurrence of unhandled exceptions surfacing at
    runtime in a given application at the expense of requiring large throws declarations and encouraging use of poorlyconstructed
    try/catch blocks. Checked exceptions are present in other languages like C++, C#, and Python.
    Runtime Exceptions (unchecked exception)
    A RuntimeException class represents exceptions that occur within the Java virtual machine (during runtime). An
    example of a runtime exception is NullPointerException. The cost of checking for the runtime exception often
    outweighs the benefit of catching it. Attempting to catch or specify all of them all the time would make your code
    unreadable and unmaintainable. The compiler allows runtime exceptions to go uncaught and unspecified. If you
    like, you can catch these exceptions just like other exceptions. However, you do not have to declare it in your
    �throws" clause or catch it in your catch clause. In addition, you can create your own RuntimeException
    subclasses and this approach is probably preferred at times because checked exceptions can complicate method
    signatures and can be difficult to follow.

  • How to Check and Uncheck the JCheckBox in the JTable?

    Dear Friends,
    I created a Table using JTable and it consists first column is JCheckBox (JCheckBox is included in JTable by using TableCellRenderer) and two more columns with Id and Name. How to enable the check and uncheck the JCheckBox in the Table and how to get the row id or values of the rows where the CheckBox is checked?
    Thanks in Advance.
    Sathish kumar D

    Read the API for JTable and follow the link to the tutorial on how to use tables, where you will find adequate guidance and examples.
    db
    edit And isn't this post on the same topic as your previous one? If so, please add a note that responses should be posted here and not on the other thread.
    [http://forums.sun.com/thread.jspa?threadID=5353422]
    Edited by: Darryl.Burke

  • When to use which scope

    Hi,
    I have a CRUD application.. Where in the data is fetched, displayed n edited n stored back to db. Also there is a sequential access between pages & the information entered on the first page is needed on the second page & so forth. What would be the best scope & why ?
    When to use which scope? What is the life-cycle of each scope.
    Also, I couldn't find any good tutorial on scopes. If you are aware of the same, please guide.
    Its urgent.
    Thanks in advance.

    921331 wrote:
    Hi,
    I have a CRUD application.. Where in the data is fetched, displayed n edited n stored back to db. Also there is a sequential access between pages & the information entered on the first page is needed on the second page & so forth. What would be the best scope & why ?
    When to use which scope? What is the life-cycle of each scope.
    Also, I couldn't find any good tutorial on scopes. If you are aware of the same, please guide.
    Its urgent.
    Thanks in advance.You could use ViewScope and parameters to the next view or if using CDI have a look at conversation scope. You should read about them in detail yourself because even if someone chooses one for you it's still you who has to go on to use it correctly.

  • How do I make my already existing check boxes "checkable" [so I can check and uncheck them on PDF Expert]

    How do I make my already existing check boxes on a (PDF Document) checkable - So I can check and uncheck them on PDF Expert or Annotate 101.
    I am using ADOBE Acrobat PRO with millions of options, but no easy "here is how to do the one thing you want to do" anywhere within reason.
    Please help me.
    Thank You

    Can you check and uncheck the boxes in Acrobat?

  • 305500 non-Oracle exception when I use forms 6i to open a excel

    Hi
    I get a 305500 non-Oracle exception when I use forms 6i to open a excel file. Does anyone know what the problem is? Any solution/workaround for this?
    Thanks

    Hi, this problem mainly happens if you try to close an excel sheet which you have not open or you are trying to open an excel sheet twice with the same name.

  • My computer has crushed so i have to download I tunes again,and maybe all my information will be lost.but i had I cloud and last time when i used to i tunes they have asked me to do I cloud so i did,so now when i will again setup my computer and I tunes

    my computer has crushed so i have to download I tunes again,and maybe all my information will be lost.but i had I cloud and last time when i used to i tunes they have asked me to do I cloud so i did,so now when i will again setup my computer and I tunes will i get all my Contacts and Inofrmations cause i had i have an account on I cloud

    If you used icloud for your contacts and calendar then you should have no problem. They will all come back on the phone once you put the icloud user name and password in. Itunes does not store the contact information except in a backup file and if you were backing up using icloud you can use that backup to restore with.

  • How do I remove top and bottom margins when printing using Adobe Acrobat XI Standard.

    How do I remove top and bottom margins when printing using Adobe Acrobat XI Standard. (I selected 'Fit to scale' and there's a huge gap on the top and bottom).

    Those margins are usually reported from the printer settings to Acrobat. Meansif you have, for example, an inkjet printer and that printer can not print seamlessly, then there will be a minimum margin.
    Check your printer's page settings.

  • Checking and unchecking affecting all playlists

    My wife and I use 2 iPod nanos and we have our own playlists. We share iTunes but our setting are such that her iPod syncs with her playlist and my iPod syncs with mine.
    The problem is that where we have common songs in a playlist. If she checks a song on her playlist that is currently unchecked in my playlist, it becomes checked in my playlist too.
    If I then go in and uncheck it from my playlist, it unchecks in hers.
    As you can imagine, each time she syncs she gains or loses any common song that I may have checked or unchecked.
    This can't be how it is supposed to work, can it? More to the point, how can we fix this so that my playlist selections remain unaffected by what she does in her playlist?
    (For full information, this also happens from the Library. If songs are checked or unchecked in the library, they become checked and unchecked across every playlist. )
    Thanks very much for any assistance.
    I am using Windows XP and iTunes v. 7.0.2.16

    Command-click on any checkbox.
    Regards.

Maybe you are looking for

  • Itunes tv episode purchase not showing up in cloud

    My wife just purchased a TV episode on her laptop (associated with my ID). I went to download it to my ipad so I can also watch it on my commute, but it doesn't show up in the cloud.  I checked the purchase history and all it shows is "Not Available"

  • Asset Accounting implementastion problem

    Hi sap Friends, At the Time of create Asset master i have faced in the below problem.please help to my friends. Customizing inconsistency - missing/incorrect entry in table T093B Message no. AY159 Diagnosis There is a Customizing inconsistency. Chart

  • Release of cleared item

    Dear gurus, I'm facing a problem because I can not release the block set for one cleared item. It has been posted through MIRO tx. and now the FI line item can not be modified for "Lock for Payment" field. Could you please help me finding a workaroun

  • Report on Receivables ECC 6.0

    Does anyone know where I might find some guidance on the correct configuration of the AR module to produce a correct Report on Receivables in ECC 6.0?  I have looked through help.sap.com, sdn.sap.com, sap community and Google to no avail.  Any help w

  • Old 5d or new Rebel? Help Please!

    Hi! Lately I have been doing some research and questioning if I should sell my old 5d in exchange for a new Rebel (maybe the t5i?).  I take a lot of animal shelter photos, as well as travel/landscape/touristy photos.  I played with the t5i the other