Why we use exception ???

Why we use Exception ??anyone knows what are the 3 keys point below describe about..??
There are 3 main Advantages of using Exception
1.Separates error handling code from "regular code
2.Propagating erros up the call stack (without tedious programming)
3.Grouping error type and error differentiation
TQ.

hi,
1) you can catch those exceptions and write extra classes for handling/log them, so you do not have to do between the lines of source
2) if an uncaught exception happens an errorstack will be invoked. On the stack you can see, where the exception started and which classes are involved
3) you can have very special erros, for example all errors which occurs on files (normally it is an IOException), you can define your own exceptions so you can say, i.e. line 503 doesn't contain what it should.
With this way you can resolve very well where an exception raises and why it happens.
hope it answers
regards
freak

Similar Messages

  • When to use Exceptions?

    Should i use Exceptions in my classes like this?
    try {
    auth.loginUser(userName, userPassword);
    System.out.println("User logged in.");
    catch (InvalidUserException e1) {
    System.out.println("User does not exists.");
    catch (PasswordDoesNotMatchException e2) {
    System.out.println("Password is incorrect.");
    catch (SystemException e3) {
    System.err.println("System error.");
    // logging to file, etc.
    System.out.println("Please, try login later.");
    ..or maybe i should use Exceptions only for "real" Java errors? (file not found, division by zero, etc.)
    Thanks!

    Well, the word "exception" says a lot here; you throw
    an exception when something exceptional happens, in
    other words: something you normally don't expect to
    happen. And you offer control returned value? Bad solution, because I can
    want not only true/false answer, but and reason why it happen. In your offer I must use String answer = "user OK"; or "answer 200"
    This quote is from Thinking in Java:
    In C and other earlier languages, there could be several of these
    formalities, and they were generally established by convention and not as
    part of the programming language. Typically, you returned a special value
    or set a flag, and the recipient was supposed to look at the value or the flag
    and determine that something was amiss. However, as the years passed, it
    was discovered that programmers who use a library tend to think of
    themselves as invincible�as in, �Yes, errors might happen to others, but
    not in my code.� So, not too surprisingly, they wouldn�t check for the error
    conditions (and sometimes the error conditions were too silly to check
    for1). If you were thorough enough to check for an error every time you
    called a method, your code could turn into an unreadable nightmare.
    Because programmers could still coax systems out of these languages they
    were resistant to admitting the truth: This approach to handling errors
    was a major limitation to creating large, robust, maintainable programs.
    We can analize it how Login use case.
    Flow: If use enter good login and passwd, when ....
    Exception: bad passwd, bad login, ban IP and other.
    ciau,
    kafka

  • Why not use notifyall

    now I'm reading this book "Java Threads 2nd edition" by Scott Oaks and Henry Wong. Writer provide a class called BusyFlag to simulate the mutex.
    I wonder why not use notifyall() to replay notify().
    public class BusyFlag {
         protected Thread busyflag = null;
         protected int busycount = 0;
         public synchronized void getBusyFlag() {
              while (tryGetBusyFlag() == false) {
                   try {
                        wait();
                   } catch (Exception e) {
         public synchronized boolean tryGetBusyFlag() {
              if (busyflag == null) {
                   busyflag = Thread.currentThread();
                   busycount = 1;
                   return true;
              if (busyflag == Thread.currentThread()) {
                   busycount++;
                   return true;
              return false;
         public synchronized void freeBusyFlag() {
              if (getBusyFlagOwner() == Thread.currentThread()) {
                   busycount--;
                   if (busycount == 0) {
                        busyflag = null;
                        *notify();*
         public synchronized Thread getBusyFlagOwner() {
              return busyflag;
    }

    naficbm wrote:
    now I'm reading this book "Java Threads 2nd edition" by Scott Oaks and Henry Wong. Writer provide a class called BusyFlag to simulate the mutex.
    I wonder why not use notifyall() to replay notify().Looks like it should work with notifyall as well.

  • Why customize application exception this way?

    hi
    i found too different ways to customize a same application exception
    they actually work the same way but with a little difference that i can not figure out why
    the first one is
    public class BaseAppException extends Exception {
        static final long serialVersionUID = -5829545098534135052L;
         * the message of the BaseAppException.
        private String exceptionMessage;
         * A public constructor for BaseAppException containing no arguments.
        public BaseAppException() {
         * A public constructor for BaseAppException specifying exception message.
         * <p>
         * @param msg
         *            exception message.
        public BaseAppException(String msg) {
            this.exceptionMessage = msg;
        }it uses a private member "exceptionMessage" to store the exception message
    and here is the second piece of code
    public class BaseAppException extends Exception {
        static final long serialVersionUID = -5829545098534135052L;
         * A public constructor for BaseAppException containing no arguments.
        public BaseAppException() {
         * A public constructor for BaseAppException specifying exception message.
         * <p>
         * @param msg
         *            exception message.
        public BaseAppException(String msg) {
             super(msg);
    //        this.exceptionMessage = msg;
        }this one passes the message to the base throwable
    both works but i am wondering why define a private string memeber for message storing and not pass it to the base throwable??

    I'm not sure what you're trying to do here, but at
    first glance "TestK t = new TestK();" inside the for
    loop seemed unusual.
    If you place it before the loop it works fine.I guess what he is trying to ask is that why is that if you use the new operator in the code, you donot get the exception while if you dont use it you do get one. While in any case either you use it or not you are supposed to get a new String as per the String API.
    Well thats an interesting observation and I have no explanation as to why is this happening. I do remember that thread where somebody pointed this out as a use of the String(String original) construtor. Furtehr adding on to that the API states about this constructor the following
    Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string.
    so I donot get why not using it would cause the exception to be thrown. I have tested the code though and it seems to behave as pointed in the original post.
    Interesting question though, food for thought.

  • Why we use this function module

    Hi
        why we use this function module 'LIST_TO_ASCI'.
    regards,
    sivakumar

    hi,
    using LIST_TO_ASCI you can get the list in TEXT format, but this will be with all the formatting you have done in your list, it wont be just field names and its values.
    check this sample code.....
    DATA  BEGIN OF itab_list OCCURS 0.
            INCLUDE STRUCTURE abaplist.
    DATA  END OF itab_list.
    DATA: BEGIN OF vlist OCCURS 0,
            filler1(01)   TYPE c,
            field1(06)    TYPE c,
            filler(08)    TYPE c,
            field2(10)    TYPE c,
            filler3(01)   TYPE c,
            field3(10)    TYPE c,
            filler4(01)   TYPE c,
            field4(3)     TYPE c,
            filler5(02)   TYPE c,
            field5(15)    TYPE c,
            filler6(02)   TYPE c,
            field6(30)    TYPE c,
            filler7(43)   TYPE c,
            field7(10)    TYPE c,
          END OF vlist.
    SUBMIT zreport EXPORTING LIST TO MEMORY.
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject = itab_list
      EXCEPTIONS
        not_found  = 4
        OTHERS     = 8.
    CALL FUNCTION 'LIST_TO_ASCI'
      EXPORTING
        list_index         = -1
      TABLES
        listasci           = vlist
        listobject         = itab_list
      EXCEPTIONS
        empty_list         = 1
        list_index_invalid = 2
        OTHERS             = 3.
    IF sy-subrc NE '0'.
      WRITE:/ 'LIST_TO_ASCI error !! ', sy-subrc.
    ENDIF.
    ~~Guduri

  • Why we use string args[]  in void main()

    why we use string in void main in java?

    Because that's roughly how C did it and Java is based on C.
    You can get all the input arguments using JMX, but it's rather complicated and not useful except in obscure cases.
    (I use it to determine if a unit test is running in debug and change the timeouts in my tests so I can step through a test without it stopping at a random point due to a time out)

  • Why we use Procedures?

    Hi Friends,
    I would like to know about procedures in using real life.I m confuse about the use of it.Please help me out.......
    1.Why we use Procedures?
    2.Where we use procedures in real life?
    3.Can we insert 100 of records in a table through a procedures?
    4.is it good to insert through procedures?

    kindly refer below code but i sure if u google around u will find a lots of answer.
    for me procedures is a small programs just like other programming language and your code will be more easy to manage and more faster in debugging process.
    The syntax for a procedure is:
    CREATE [OR REPLACE] PROCEDURE procedure_name
    [ (parameter [,parameter]) ]
    IS
    [declaration_section]
    BEGIN
    executable_section
    [EXCEPTION
    exception_section]
    END [procedure_name];
    When you create a procedure or function, you may define parameters. There are three types of parameters that can be declared:
    IN - The parameter can be referenced by the procedure or function. The value of the parameter can not be overwritten by the procedure or function.
    OUT - The parameter can not be referenced by the procedure or function, but the value of the parameter can be overwritten by the procedure or function.
    IN OUT - The parameter can be referenced by the procedure or function and the value of the parameter can be overwritten by the procedure or function.
    The following is a simple example of a procedure:
    CREATE OR REPLACE Procedure UpdateCourse
    ( name_in IN varchar2 )
    IS
    cnumber number;
    cursor c1 is
    select course_number
    from courses_tbl
    where course_name = name_in;
    BEGIN
    open c1;
    fetch c1 into cnumber;
    if c1%notfound then
    cnumber := 9999;
    end if;
    insert into student_courses
    ( course_name,
    course_number)
    values ( name_in,
    cnumber );
    commit;
    close c1;
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    END;
    This procedure is called UpdateCourse. It has one parameter called name_in. The procedure will lookup the course_number based on course name. If it does not find a match, it defaults the course number to 99999. It then inserts a new record into the student_courses table.

  • Why when using Adobe Bridge,  I apply a star rating,  the rating does not show up in Photoshop Elements? [tags]

    Why when using Adobe Bridge,  I apply a star rating,   the rating does not show up in Photoshop Elements.  I use Elements as my organizer and Bridge to view as it is much more user friendly.  Anyone any solutions??

    Most likely you have set the wrong file as the external editor. You don't want the obvious one; that's just a link to the welcome screen. Go back and choose this one, which is hidden away inside the folder Support Files:

  • I want to ask something about firefox. why firefox use very much memory? can you develop to reduce memory comsume? this problem is very distrub in my PC with low memory.

    I want to ask something about firefox.
    why firefox use very much memory?
    can you develop to reduce memory comsume?
    this problem is very distrub in my PC with low memory.
    == This happened ==
    Every time Firefox opened

    How much memory is Firefox using right now?
    # Press '''CTRL+SHIFT+ESC''' to load the Task Manager window
    # Click the Processes tab at the top. (Click once near the top of the window if you don't see tab
    # Find firefox.exe, and see how many kilobytes of memory it's using.
    Showing around 80MB when Firefox first starts is normal. Right now, I have 75 tabs open and it's using 500MB - this varies a lot depending on what you have in the tabs.
    Other than high memory usage, what other problems are you experiencing? (Examples include slowness, high CPU usage, and failure to load certain sites)
    Many of these issues, including high memory usage, can be caused by misbehaving add-ons. To see if this is the case, try the steps at [[Troubleshooting extensions and themes]]. Outdated plugins are another cause of this issue - you can check for this at http://www.mozilla.com/plugincheck

  • Why we use different clearing account for GR/IR and planned cost clearing a

    My client ask for using same account for GR/IR account and all planned cost clearing account.
    i try to convince it should be different accounts but he needs a logical answer.
    Why we use different clearing account for GR/IR and planned cost clearing accounts?

    Dear friend.
    u just tell him while doing GR it will debited n  while doing IR it should get credited.hence we  need to take diff G/L account or same account.
    regds
    nasir

  • HT201343 My MBP is Early 2011 but dunno why cant use mirroring with apple TV, the icon cannot be found

    My MBP is Early 2011 but dunno why cant use mirroring with apple TV, the icon cannot be found. So cannot use mirroring.
    I have follow trouble shooting , they recommend to go system preference -> display , thus can find out the mirroring icon if no mean it doesnt support. But according to the web, Early 2011 MBP should be able to use, dunno why.

    Just realise I havent updated my OS to mountain lion and this is the reason why I cannot use mirroring before ^^
    Thanks all

  • How to find the list of Queries/Reports which are using Exceptional Aggregation in SAP BI?

    Hi All,
    We are interested to know how to find the list of Queries/ Reports which are using Exceptional aggregation in SAP BI.
    Please let us know is there any table's to check the list of reports using Exceptional Aggregation in SAP BI.

    Hi,
    Here you go..
    1) Go to table RSZCALC and get list of ELTUID where AGGREXC is not INITIAL and AGGRCHA is not initial; now you get only exception aggregation set based on some chars. Also you can further add STEPNR = 1 since your intention is just to get query name , not the calculation details; this will reduce number of entries to lookup and save DB time for next steps.
    Here you will get list of exception aggregation UUID numbers from which you can get properties from RSZELTDIR.
    2) Pass list of RSZCALC-ELTUID to table RSZELTXREF - TELTUID and get list of RSZELTXREF -SELTUID - this table stores query to it's elements maping kind.
    3) Now again pass RSZELTXREF - SELTUID into same table but into different field RSZELTZREF - TELTUID and get RSZELTXREF - SELTUID
    This step you get query reference sheet or column or query general UUID for next step.
    4) Pass list of RSZELTXREF - SELTUID into RSZELTDIR - ELTUID with DEFTP as 'REP'. Now you get list of query names in RSZELTDIR - MAPNAME and description in TXTLG.
    Note: you can also get the reference chars used for exception aggregation from RSZCALC - AGGRCHA field.
    Hope this helps.
    Please keep in mind, it might take more time depends on how many query elements you have in the system...
    Comments added for better DB performance by: Arun Thangaraj

  • What is the intelligent calc? Why we use that?

    If u loads data to parent level where data will be stored?
    What r the unary operators?
         How do u decide dense & Sparse?
         What is the header? Why we use header in the rule file?
    Please give me reply dont say read dabg
    Thank u.......

    OK,
    You have a database/application.
    1. You might have had run the calculation( ie calc script).
    2. after that , you might have loaded the data ,i.e you have infused new data and new data blocks.
    3. For these new data blocks ,you have not run the calculation so far
    4. so, now the intelligent calculation come into picture, with the help of the intelligent calculation concept, we can run the calculation on only the new data loaded or on only new data blocks,which you loaded
    Hope this helps you in understanding the intellligence calculation in short.
    One can enable and disable at his comfort ,and for that please refer to the following commands
    SET UPDATECALC
    SET CLEARUPDATESTATUS
    this is to answer you intelligent calc.
    1. when you load data into the parent level , it ll be stored at the parent level only.
    2. when you go to "Dimension"' tab of the database properties, you can get which one is dense or sparse
    3. in general ,you have a datafile ,and the upper most line is the one ,which has headers,so manipulate the same ,you use headers in the rule file.
    I have not told you to refer DBAG , :)
    But, you got to read DBAG or pick a bootcamp for you to understand further .
    Sandeep Reddy Enti
    HCC

  • How to use Exceptions for a function module

    Hi folks,
            I have created  a new function module.Its working fine, but i am not aware of using exceptions for a function module. I hav just declared an exception in the 'exception' tab. Could any body explain me how to use that in my FM source code....Thanks...

    Hi Shyam,
    Have a look at this,
    START-OF-SELECTION.
      gd_file = p_infile.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                = gd_file
          has_field_separator     = 'X'  "file is TAB delimited
        TABLES
          data_tab                = it_record
        EXCEPTIONS
          file_open_error         = 1
          file_read_error         = 2
          no_batch                = 3
          gui_refuse_filetransfer = 4
          invalid_type            = 5
          no_authority            = 6
          unknown_error           = 7
          bad_data_format         = 8
          header_not_allowed      = 9
          separator_not_allowed   = 10
          header_too_long         = 11
          unknown_dp_error        = 12
          access_denied           = 13
          dp_out_of_memory        = 14
          disk_full               = 15
          dp_timeout              = 16
          OTHERS                  = 17.
        IF sy-subrc NE 0.
          write: 'Error ', sy-subrc, 'returned from GUI_UPLOAD FM'.
          skip.
        endif.
    Regards,
    Sai

  • Why to use B2B when we can go with ...

    why to use B2B when we can go with A2A with FTP services running in the source and target systems.
    why do we go for parties if the above one is possible.
    plz help out im into loads of confusion

    Hi
    A2A is application to application: when two applications in a company talk to each other we call it an A2A scenario and if its across Companies we call it B2B or buisness to buisness scenarios.
    All the following links will explain   the difference between A2A and B2B
    With scenario’s
    A2A   B2B Scenarios
    can anyone explain A2A & B2B  AND  BPM & ccBPM  with an example..
    Help for Scenario! B2B or A2A
    A2A Vs B2B
    A2A and B2B
    I hope this will answer your question
    regards
    --- prasad

Maybe you are looking for