Results 1 to 7 of 7

Thread: How are exceptions and errors handled in a program ?

  1. #1
    Join Date
    Aug 2010
    Posts
    61

    How are exceptions and errors handled in a program ?

    I am a second year Bsc(IT) student , I have learned two programming language learned till now one is C and the other is C++. In the upcoming semester i.e the fourth semester I have will get the opportunity to learn JAVA. I have heard a lot about Java , and know that it includes more object oriented approach than C++, but there is no such programming language that does not produce any error or a bug, I am looking forward to learn learn java , so I want to know that if some error occurs , how to categorize the error and what are the possible ways to sort out them and throw them out of the program and make the code execution successful. Please give your views, it would be more helpful, if programmers and senior students share ideas on these questions. P.S I will learn core java first then go to advanced.

  2. #2
    Join Date
    May 2009
    Posts
    529

    Re: How are exceptions and errors handled in a program ?

    I am a graduate in IT as well. Yes Java from Sun Microsystems is much more object oriented than C++ , in fact it is fully object oriented while C++ is not.Each and every class in JAVA are well versed. Your college will be asking you for the electives in your JAVA fifth semester, either you will have to choose Web Development or opt for JAVA . So if you really want to be a master in JAVA , better earn and clear all your basics in the Core JAVA which is mandatory in the fourth semester. I your question you have asked about the errors that prevent a code to compile successfully. You cannot just predict an error in just theory, because there is a variety in which the code is written and there are lots of errors encountered meanwhile. And I can explain you what is an exception with an example. When any integer is divided with zero, the Java compiler throws an exception which needs to be handled to proceed the continuous flow of instructions. I do not have much idea how is it handled, so please beg me pardon.

  3. #3
    Join Date
    May 2009
    Posts
    637

    Re: How are exceptions and errors handled in a program ?

    Am error in a program is something unintentional in a program that obstructs a code of a program to run or execute successfully. A program is said to be buggy if it has lots of bugs in it, by bug I mean the errors , flaws and mistakes which are unnoticed and produce results which are not expected or not intended by the programmer , To remove a bug from a program or a software is called debugging of the code. I think this much is enough for you to learn at this stage or you will get confused , because it is always better to have a slow and study start rather than taking each and everything at once. But still if you feel you are hungry you are most welcome to post your question again.

  4. #4
    Join Date
    May 2009
    Posts
    543

    Re: How are exceptions and errors handled in a program ?

    An error can be categorized in differently . they can be simple and complicated. but sometime these errors are too small but are somewhere hidden and remain unnoticed. The impact of an error on code depends upon it's severity, some time the impact is little and sometime it might turn out fatal. There are mostly three types of errors in most of the programming language. A syntax error is occurred when the programmer uses an incorrect syntax which is not known by the compiler of the programming language. It can be a spelling mistake or a wrong loop statement. A logical error is encountered when incorrect logic is applied i.e a programmer is subtracting when actually he should do type addition. A run time error occurs while trying to execute a code after compilation . For instance you are loading a non existent file in a program will produce a run time error.

  5. #5
    Join Date
    May 2009
    Posts
    511

    Re: How are exceptions and errors handled in a program ?

    These errors mentioned above can be resolved using effective measures. Since you are learning a Java, at the initial stage you are advised tp use the Java NetBeans. It is a tool that is used to develop Java programs and will guide you meanwhile you are typing the code. If you make any mistake or error in the code, it will straightaway prompt you and your error will be highlighted. But you should use this NetBeans tool only in the initial days, you should not make any habit of it , or will not gain much knowledge of the JAVA language once you get habitual with NetBeans. The exceptions are handled using try and catch statement, but do not know how.

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: How are exceptions and errors handled in a program ?

    Exceptions are the errors that are encountered during the run time of any programming language. There are different types of exceptions in a programming language. Whenever an exception occurs , the normal flow of program execution gets disrupted. So it is very necessary to ho tackle with those exceptions if you want your program to run successfully, Exceptions are of many types and can be handled once their behavior is recognized. They can occur in many ways or example. division of any integer by zero, trying to access ant element in an array that is out of bound, there is no space in the heap. In all the given cases the compiler will throw an error . To deal with such exception is called as exception handling. If you are writing any code in a block and think that it will throw any exception then you can throw that exception and and that block is the try block, which is the suspected block that may throw any exception. The block that follows a try block is called as Catch block. There can be more than one catch block in a program depending upon the scenario or you can say there can be multiple catch block after a try block. This exceptions thrown in a trey block are caught in a Catch block. If the exceptions are not caught in catch block there is one more block that can be added called as Finally block . This bloc k is optional and is not mandatory to mention , but there must always be a catch block after each try block statement.

  7. #7
    Join Date
    May 2009
    Posts
    539

    Re: How are exceptions and errors handled in a program ?

    Exceptions are the run in error in a program to notify that there is some exceptional situation been occurred, and also indirectly indicates the programmer that there wold not be any sense to continue with the code unless the exceptions are removed from it, because till the time those exceptions are there in the program they will not let the code execute smoothly. As the examples of exceptions are are already shown in the above replies. There should be some way in which these exceptions should be handled to continue with further coding. A function or a method may also have an exception, for example the input parameter you pass in the method may be invalid. A method must be capable of throwing an exception, for that purpose it will have to to declare the exceptions being thrown in the method parameters , and then it should be followed by a throw-statement in that particular method.If a method invokes another method that is currently throwing a checked exceptions, the method that is invoking it , is then bound to either pass the exception on, or should be able to capture it. Which is also called as catching an exception. It can be done using a a block of statements called as try-catch block. If there is no exception being thrown by any of the functions or methods being invoked or there is no such statement in the try block then the catch-block is remained unnoticed.

Similar Threads

  1. Can Zonealarm free 10.1.065.000 be handled remotely??
    By Vascon!cell in forum Networking & Security
    Replies: 3
    Last Post: 17-02-2012, 01:39 PM
  2. Replies: 1
    Last Post: 20-04-2011, 05:30 PM
  3. How are Runtime error handled in C# ?
    By Karumbu in forum Software Development
    Replies: 3
    Last Post: 15-01-2011, 08:05 AM
  4. Getting many Errors when trying to run the Java Program
    By N I C K in forum Software Development
    Replies: 5
    Last Post: 16-01-2010, 05:46 PM
  5. Class, interface errors in my program
    By Balamani in forum Software Development
    Replies: 3
    Last Post: 02-12-2009, 06:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,101,653.36291 seconds with 17 queries