Java Best practices

Saturday, 12 March 2011

Exceptions (TOC)

Introduction to exception
How java implements Exception handling?
Types of Exceptions in java
            Checked vs unchecked vs Error type exceptions

Java's catching or throwing exception

This section discusses the reasoning behind this requirement and what it means to you and your Java programs.

Dealing with Exceptions

  • Example of class which has to deal with example
  • Catching and handling exception with try-catch-finally
  • Specifying the exceptions thrown by method using throws clause

How to throw Exceptions

  • The throw statement
  • Creating custom exception

Custom Exceptions

  • Adding custom exceptions to the project design
  • Creating the custom exception example
  • Naming convention for exceptions in java

Nested Exceptions

Runtime Exceptions--The Controversy

Exceptions and control flow

Finally and catch

Some practices related to exception:

    • Avoid @throws in javadoc

    • Javadoc all exceptions

    • Be specific in throws clause

    • Stack trace as String

    • Use template for repeated try-catch

    • Pass all pertinent data to exceptions

    Posted by Rekha Kumari at 02:35
    Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
    Labels: exception, java, toc2

    No comments:

    Post a Comment

    Newer Post Older Post Home
    Subscribe to: Post Comments (Atom)

    Followers

    Blog Archive

    • ►  2012 (8)
      • ►  January (8)
    • ▼  2011 (432)
      • ►  December (5)
      • ►  October (3)
      • ►  September (2)
      • ►  July (24)
      • ►  June (61)
      • ►  May (86)
      • ►  April (120)
      • ▼  March (72)
        • Tools for converting c to java source
        • Conversion from decimal to binary
        • Conversion from integer to hexadecimal and vice-versa
        • Covariant Parameter Types
        • JPA : Persistence unit
        • JPA 2.0 with EclipseLink
        • JPA resoures for eclipse link
        • JPA : Relationship Example using eclipse link
        • Simple example on JPA with eclipse link
        • Installation - Eclipse link and derby for JPA
        • Relationship Mapping
        • Persistence of fields
        • Entities and Transactions in JPA
        • EntityManager in JPA
        • Customizing the Entity object in JPA
        • JPA Architecture
        • JDBC vs ORM
        • JPA : Overview
        • Initialling to zero rather than null
        • Equivalent of function pointers of C in java
        • Get file size in java
        • More on XML serialization with JAXB
        • Jaxb : Shortcomings of API
        • Jaxb : Validation
        • Marshalling : Jaxb
        • UnMarshalling : Jaxb
        • Jaxb : TABLE OF CONTENTS
        • Jaxb : Binding XML Schemas
        • Prerequisites for jaxb
        • JAXB : Generating java classes from xsd
        • How to create a zip file with java.util.zip package
        • Retrieve a compressed file from a ZIP file
        • Retrieve the contents of a ZIP file
        • Uncompress a file in the GZIP format
        • Writing zip file in java
        • Convert String to boolean
        • Convert String to byte array
        • Convert from byte array to string
        • Jaxb - Example to generate xml from java class
        • java.lang.NoClassDefFoundError: org/apache/commons...
        • JAXB Architecture
        • JAXB Introduction
        • Compression and DeCompression in Java using java.u...
        • Compressing java string
        • JAXP introduction
        • Example on Format of a Serialized Object
        • Versioning in Serialization
        • Java Serialization in gist
        • How to validate URL in Java?
        • How to schedule a job in Java?
        • Putting It All Together
        • The finally Block in java
        • The catch Block(s)
        • The try Block in java
        • A simple class which has to deal with exception - ...
        • try - catch - finally : Catching the exception in ...
        • throws : Throwing the Exceptions from a method in ...
        • Exceptions (TOC)
        • Java's catching or throwing exception
        • Runtime Exceptions--The Controversy
        • Creating Your Own or Custom Exception Classes in java
        • The throw Statement
        • How to Throw Exceptions
        • Introduction to exception
        • Avoid basic style errors
        • Java beans
        • Generic database insert and select code
        • RMI and CORBA
        • Rmi : The concept and terminologies
        • Remote method invocation allows applications to ca...
        • Starting rmi registry
        • Varargs in Java: Variable argument method in Java 5
      • ►  February (57)
      • ►  January (2)
    • ►  2010 (73)
      • ►  December (1)
      • ►  October (24)
      • ►  September (31)
      • ►  August (9)
      • ►  July (2)
      • ►  May (4)
      • ►  April (2)
    • ►  2009 (1)
      • ►  December (1)

    About Me

    Rekha Kumari
    View my complete profile

    Labels

    • Access Control (1)
    • awt / abstract window toolkit (1)
    • batch processing (2)
    • Bean (2)
    • bigdecimal (2)
    • BigInteger (1)
    • binding (1)
    • bits (1)
    • bitwise operators (1)
    • books (3)
    • boolean (1)
    • c++ / cpp (1)
    • catalyst (1)
    • character IO (1)
    • charting (1)
    • classloader (13)
    • classpath (5)
    • clone (4)
    • coding style (6)
    • collection-diagrams (2)
    • collection-interface (1)
    • Collections (1)
    • command line arguments (2)
    • command prompt (1)
    • commons-lang (3)
    • commons-logging (1)
    • Comparable (2)
    • Comparator (1)
    • compare() (1)
    • compareTo() (4)
    • Comparison (4)
    • compilers (6)
    • composition (6)
    • compression (4)
    • concatenate (1)
    • conditions (1)
    • Console (1)
    • console input (1)
    • constant / literal pool (4)
    • Constructor (1)
    • contravariance (2)
    • control flow (2)
    • controversy (1)
    • conversion (6)
    • Copy Constructor (1)
    • Copying (3)
    • core-java (2)
    • covariance (5)
    • cpp vs java (4)
    • custom exception (3)
    • cyclic dependency (1)
    • data types (1)
    • dbutils (1)
    • DDD / Domain Driven Design (1)
    • decompile (1)
    • decompiler (1)
    • deep copy (3)
    • delete (1)
    • design (4)
    • design principle (1)
    • destructor (1)
    • deterministic (1)
    • development tools (7)
    • difference (4)
    • directory (16)
    • disadvantage (1)
    • divide-by-zero-exception (1)
    • document (1)
    • double (2)
    • download-source-code (3)
    • dynamic (1)
    • dynamic / weak typing (1)
    • early binding (1)
    • eclipseLink (1)
    • effective java (5)
    • email (1)
    • encapsulation (1)
    • Enum (11)
    • environment variables (1)
    • equality (6)
    • equality operator (1)
    • equals() (10)
    • event (1)
    • example-code (4)
    • excel (1)
    • exception (45)
    • exe (1)
    • executable (1)
    • Execution time (1)
    • externalization (6)
    • failsafe (1)
    • FAQ (1)
    • feed (1)
    • File (3)
    • File handling (30)
    • file IO (3)
    • fileFilter (2)
    • FileFiltername (1)
    • filter (1)
    • Filtered Stream (2)
    • final (3)
    • final classes (1)
    • finalize (1)
    • finally (3)
    • firstProgram / helloworld (7)
    • float (1)
    • formatting output (1)
    • frame (3)
    • Function parameter (1)
    • function pointers (1)
    • Fundamental Prog. Structure (1)
    • gc / garbage collection (4)
    • generic-method (1)
    • Generics (17)
    • generics faciliy (3)
    • getopt (1)
    • Getter (1)
    • GUI (1)
    • guice (1)
    • gzip (1)
    • h2 database (1)
    • hashcode (4)
    • heap-memory (2)
    • hell (1)
    • http (2)
    • httpconnection (1)
    • image (3)
    • immutable objects (3)
    • import (2)
    • in-memory (1)
    • inheritance (10)
    • ini file (1)
    • init block (1)
    • initialization (6)
    • Inner Class (5)
    • Input (1)
    • instanceof (3)
    • integer (2)
    • Interface (1)
    • intern (2)
    • internalization (1)
    • interview questions (7)
    • introduction (1)
    • invariance (1)
    • IO / Input Output (21)
    • ireport (1)
    • isEmpty (1)
    • iterable (1)
    • iterate (1)
    • iterator (2)
    • itext (6)
    • j2ee (1)
    • jar (5)
    • jasper (1)
    • java (506)
    • Java API (1)
    • java console (1)
    • java secret (1)
    • java-practises (8)
    • java-puzzler (1)
    • java-secrets (1)
    • java-tip (1)
    • java.io (31)
    • java.io.File (19)
    • java.lang (3)
    • java.math (1)
    • java.net (2)
    • java.nio (1)
    • java.text (1)
    • java.util.logging (2)
    • java.util.zip (6)
    • Java5 / tiger (4)
    • java6 (1)
    • java7 / jdk7 (8)
    • javac (1)
    • javac options (2)
    • javadoc (2)
    • javamail (2)
    • javax (1)
    • javax.tools (1)
    • jaxb (12)
    • jaxp (1)
    • jdbc (10)
    • jdbc drivers (1)
    • jexcelapi (1)
    • jfreechart (1)
    • jms (1)
    • jpa / java persistence api (15)
    • jsp (1)
    • junit (2)
    • just-in-time (JIT) compilers (1)
    • jvm (8)
    • jython (1)
    • keyword (1)
    • late binding (1)
    • lazy initialization (1)
    • lifecycle (1)
    • limitations (1)
    • list (1)
    • literals (1)
    • locale (1)
    • locking (1)
    • logging (8)
    • lucene (1)
    • main-method (2)
    • map (1)
    • memory (6)
    • memory frame (1)
    • memory leak (2)
    • memory model (2)
    • message-format (1)
    • method overriding / hiding (2)
    • mock test (1)
    • mq / message queue (1)
    • multiple inheritance (1)
    • named exception (2)
    • naming convention (9)
    • nanotime (1)
    • native method (6)
    • natural langauge (1)
    • natural ordering (1)
    • need (1)
    • Nested Class (6)
    • no to constructor (1)
    • non-static (1)
    • NPE / Null Pointer Exception (2)
    • null (4)
    • number (1)
    • NumberFormat (1)
    • numbers (1)
    • object (1)
    • Object class (2)
    • Observable (1)
    • online (1)
    • openjdk (2)
    • operators (7)
    • optimization (1)
    • orm (16)
    • os / operating system (2)
    • output (2)
    • overloading (2)
    • overriding (3)
    • package (3)
    • paradigm (1)
    • parametric type (2)
    • parsing (5)
    • Pass by value (1)
    • password breaking (1)
    • path (2)
    • pdf (4)
    • pdf-generation (5)
    • precompilation (1)
    • preventing inheritance (1)
    • Primary / primitive data types (1)
    • printf (2)
    • privilege (1)
    • process (1)
    • programmatic / runtime compilation (1)
    • programs (10)
    • properties (6)
    • Pros and cos (1)
    • quartz (1)
    • random (2)
    • random stuff (1)
    • raw types (1)
    • read/write (1)
    • recursion (1)
    • regex / regular expression (16)
    • resource (1)
    • restrictions (2)
    • return (1)
    • rmi (4)
    • rss (1)
    • rtf (1)
    • ruby (2)
    • runnable (1)
    • runtime (3)
    • saaj (1)
    • sample code (2)
    • scheduler (2)
    • scjp (7)
    • scope (1)
    • screenshot (1)
    • scripting (1)
    • search (1)
    • security manager (1)
    • sequence diagram (1)
    • serialization (12)
    • server (1)
    • servlet (1)
    • Setter (1)
    • shallow copy (4)
    • slf4j (1)
    • SOA / service oriented architecture (3)
    • soap (2)
    • sort (2)
    • sorting (1)
    • source code (5)
    • split (1)
    • stack (1)
    • stack memory (2)
    • standard IO (2)
    • static (12)
    • static / strong typing (1)
    • static block (1)
    • static initialization (6)
    • Stream (13)
    • String (6)
    • string abnormal (1)
    • string equality (1)
    • string IO (1)
    • string tokenizer (2)
    • String utility (1)
    • substring (1)
    • subtyping (1)
    • swap (4)
    • swing (9)
    • Switch-Case (1)
    • synchronized (1)
    • system properties (2)
    • tdd / test driven development (2)
    • testing (1)
    • thread factory (1)
    • Threads (1)
    • throw (4)
    • throws (4)
    • Time (1)
    • timer (2)
    • TimerTask (1)
    • toc/index (4)
    • toc2 (15)
    • today (3)
    • toString (1)
    • transient (1)
    • traversing (1)
    • try-catch (5)
    • tutorial-References (1)
    • type (1)
    • type parameter (1)
    • type substitution (1)
    • typecast (1)
    • types (1)
    • udf (3)
    • UML (6)
    • underscore (1)
    • unit test (1)
    • unit testing (1)
    • unix / linux (1)
    • URL (2)
    • use cases (1)
    • using reflection (2)
    • utility class (1)
    • validation (1)
    • value classes (5)
    • varargs (2)
    • variance (1)
    • version (1)
    Simple theme. Powered by Blogger.