Question on Exception

Folks -
      I am facing the following situation with which some of you might be able to help me. I am building a report that has exceptions defined in it for a calculated key figure. This CKF can is calculated as % and can have both positive and negative values.
    The requirement is that the user would enter a % value as variable (lets say he enters 10% when the query refreshes) and based on the value he entered the exceptions should show up on this CKF such that...
<b>Value of CKF</b>                      <b>Color</b>
           0 %                                      Green
        0.01 to 10 % (variable)              Yellow
        10.01 to 100 %                          Red
This was easily achieved. But the problem is with the negative values of the CKF! The user wants the color coding even on the negative values such that...
<b>Value of CKF</b>                      <b>Color</b>
        -100 to -10 %                              Red
        -10 to -0.01 %                           Yellow
        How can I achieve this functionality by using only one variable entry ??? I am looking for an option which does not involve a user exit variable.

Hi Amol -
      Thanks for your reply. The requirement is such that the user would enter only value for one variable (+ve value like 10%). Using this +ve number, how can I define an exception for the -ve values ?? Like I said above, the exception in this example should be ...
CKF Value -
Color
-100 to -10 -
  Red
-10 to -0.01  ---  Yellow
      Where 10 is just a arbitrary value and hence have to use variable here. I can achieve this by using two variables...one for +ve values and the other input for -ve value. Please let me know if I am not clear with the requirement.

Similar Messages

  • JUTreeNodeBinding question (nullpointer exception in getAttribute)

    Hi,
    I've got a question about a piece of code. I've used a JTree which displays a recursive tree, which is working fine. I want to do something when a node is selected. I have the following piece of code:
    jTree1.addTreeSelectionListener(
       new TreeSelectionListener()
         public void valueChanged(TreeSelectionEvent e)
           DefaultMutableTreeNode node = (DefaultMutableTreeNode)jTree1.getLastSelectedPathComponent();
           if (node != null)
             JUTreeNodeBinding tnb = (JUTreeNodeBinding)(node.getUserObject());
             if (tnb!=null)
       });this code is taken from some example I've read on this forum and slightly modified (I can't find the original posting).
    Now, according to the sourcecompletion feature, tnb has methods like getAttribute, getAttributeDef. But when I call one of these methods on tnb (where the '...' is in the example above), I always get a nullpointer exception , somewhere inside the getAttribute call. (the variable 'tnb' itself is not null)
    Why wouldn't this work? Shouldn't the getAttribute calls give me access to the attributes of the row from the view that corresponds the selected element?
    The logwindow shows this for the nullpointer exception:
    Exception occurred during event dispatching:
    java.lang.NullPointerException
         oracle.jbo.AttributeDef[] oracle.jbo.uicli.binding.JUCtrlValueBinding.getAttributeDefs()
              JUCtrlValueBinding.java:173
         oracle.jbo.AttributeDef oracle.jbo.uicli.binding.JUCtrlValueBinding.getAttributeDef(int)
              JUCtrlValueBinding.java:239
         void mypackage.PMyData$1.valueChanged(javax.swing.event.TreeSelectionEvent)
              PMyData.java:332
         void javax.swing.JTree.fireValueChanged(javax.swing.event.TreeSelectionEvent)
              JTree.java:2269
         void javax.swing.JTree$TreeSelectionRedirector.valueChanged(javax.swing.event.TreeSelectionEvent)
              JTree.java:2575
         void javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(javax.swing.event.TreeSelectionEvent)
              DefaultTreeSelectionModel.java:612
         void javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(java.util.Vector, javax.swing.tree.TreePath)
              DefaultTreeSelectionModel.java:1006
         void javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(javax.swing.tree.TreePath[])
              DefaultTreeSelectionModel.java:288
         void javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(javax.swing.tree.TreePath)
              DefaultTreeSelectionModel.java:171
         void javax.swing.JTree.setSelectionPath(javax.swing.tree.TreePath)
              JTree.java:1088
         void javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(javax.swing.tree.TreePath, java.awt.event.MouseEvent)
              BasicTreeUI.java:2117
         void javax.swing.plaf.basic.BasicTreeUI$MouseHandler.mousePressed(java.awt.event.MouseEvent)
              BasicTreeUI.java:2683
         void java.awt.Component.processMouseEvent(java.awt.event.MouseEvent)
              Component.java:3712
         void java.awt.Component.processEvent(java.awt.AWTEvent)
              Component.java:3544
         void java.awt.Container.processEvent(java.awt.AWTEvent)
              Container.java:1164
         void java.awt.Component.dispatchEventImpl(java.awt.AWTEvent)
              Component.java:2593
         void java.awt.Container.dispatchEventImpl(java.awt.AWTEvent)
              Container.java:1213
         void java.awt.Component.dispatchEvent(java.awt.AWTEvent)
              Component.java:2497
         void java.awt.LightweightDispatcher.retargetMouseEvent(java.awt.Component, int, java.awt.event.MouseEvent)
              Container.java:2451
         boolean java.awt.LightweightDispatcher.processMouseEvent(java.awt.event.MouseEvent)
              Container.java:2210
         boolean java.awt.LightweightDispatcher.dispatchEvent(java.awt.AWTEvent)
              Container.java:2125
         void java.awt.Container.dispatchEventImpl(java.awt.AWTEvent)
              Container.java:1200
         void java.awt.Window.dispatchEventImpl(java.awt.AWTEvent)
              Window.java:926
         void java.awt.Component.dispatchEvent(java.awt.AWTEvent)
              Component.java:2497
         void java.awt.EventQueue.dispatchEvent(java.awt.AWTEvent)
              EventQueue.java:339
         boolean java.awt.EventDispatchThread.pumpOneEventForHierarchy(java.awt.Component)
              EventDispatchThread.java:131
         void java.awt.EventDispatchThread.pumpEventsForHierarchy(java.awt.Conditional, java.awt.Component)
              EventDispatchThread.java:98
         void java.awt.EventDispatchThread.pumpEvents(java.awt.Conditional)
              EventDispatchThread.java:93
         void java.awt.EventDispatchThread.run()
              EventDispatchThread.java:85

    Bit of a coincidence.. I was just running into the same problem. But if you check getAttributeDefs(), you'll see that there only is one attribute available, namely the one that is being displayed in the tree. (the 'description'-attribute)
    Or at least, that's the case with my sitation.
    I would love to be able to address all available attributes, eg. foreign key fields, but that doesn't seem possible.
    At the moment, I'm using the following work-around, which of course is far from ideal:
    Key key = tnb.getRowKey();
    ViewObject vo = panelBinding.getApplicationModule().findViewObject("SomeVO");
    Row[] rows = vo.findByKey(key);
    if (rows == null || rows.length != 1)
      System.out.println("Notice: not 1 rows");
      return;
    Row row = rows[0];
    // now you can fetch all the attributes                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Forms question  about exceptions

    Hello,
    I am a newbie and hence my question may find very basic, please help me.
    I have a Pl/sql code where I am executing a queryand if the query doesn't retrieve any values I need to show a message.
    My code is something like this:
    select id from table into tmpid where id=:val_id
    some code here
    CALL_form(url);
    If the query fails I need to show a message, how can I do this. Forgive me for my knowledge in forms, as I am a newbie.
    Thanks in advance.
    Newbie

    Declare
      Found1  varchar2(1);
    Begin
      ...whatever code you need here...
      begin
        select 'Y' into Found1
          from table where id=:val_id;
        exception when no_data_found then null;
      end;
      If Found1 is null then
        Message('No can do!!!');
        Raise form_trigger_failure;
      End if;
      ...some code here...
      Call_form(url);
    End;

  • Question in Exception

    I have a question in the below program. It gives the following results.
    inside try*
    in catch block*
    The value:10</stro
    what happen to that catch block return 5?
    public class T2 {
    public int methodTest(){
    try {
    System.out.println("inside try");
    throw new Exception();
    }catch(Exception ex){
    System.out.println("in catch block");
    return 5;
    finally{
    return 10;
    public static void main(String[] args) {
    T2 t2= new T2();
    System.out.println("The value:"+t2.methodTest());
    }

    raghu182 wrote:
    bq. > \\ JoachimSauer wrote:Having a return or a throw statement in the finally block is usually considered bad practice exactly because of this problem: It can totally hide the effect of any previous return or throw. \\ \\ So in that case, even if you return anything in catch will be ignored by JVM. Am i right?
    If by "in that case", you mean returning or throwing from finally, then yes.
    If you return, throw, break, or continue out of finally, then any completion (return, throw, break, continue) that had been done by try or catch is superceded.

  • Question about Exception Error

    I'm writing a small PBE program for a class project and I keep getting an InvalidKeySpecException that claims my char[ ] is not ASCII. Now I am under the impression that when a char value is entered it's in ASCII values... I've only put up a piece of my code, if needed I can put up the rest, it's fairly simple and easy to follow.
    here is my terminal output (with a number of debug outputs):
    Encryption Program Started
    Getting Password
    Input password (32 character max):
    hello
    Holdspot is: 6
    Pass: hello
    Holder: (shows string of char (0) values, verifies that the array was cleared)
    Done getting password, pass is:
    hello
    Creating PBEKeySpec
    My keySpec value is: hello
    Creating Salt
    createSalt entered
    Done getting salt
    Creating PBEParameterSpec
    setParams entered
    My iteration field is: 1500
    Done getting param
    My param iterations are: 1500
    Creating SecretKey
    createKey Entered
    My keySpec value is: hello
    InvalidKeySpecException: Password is not ASCII
    java.security.spec.InvalidKeySpecException: Password is not ASCII
         at com.sun.crypto.provider.PBEKey.<init>(DashoA6275)
         at com.sun.crypto.provider.PBEKeyFactory.engineGenerateSecret(DashoA6275)
         at javax.crypto.SecretKeyFactory.generateSecret(DashoA6275)
         at Cryptography.createKey(Cryptography.java:141)
         at Cryptography.main(Cryptography.java:265)
         at __SHELL3.run(__SHELL3.java:7)
         at bluej.runtime.ExecServer.vmSuspend(ExecServer.java:178)
         at bluej.runtime.ExecServer.main(ExecServer.java:143)
    java.security.spec.InvalidKeySpecException: Password is not ASCII
         at com.sun.crypto.provider.PBEKey.<init>(DashoA6275)
         at com.sun.crypto.provider.PBEKeyFactory.engineGenerateSecret(DashoA6275)
         at javax.crypto.SecretKeyFactory.generateSecret(DashoA6275)
         at Cryptography.createKey(Cryptography.java:141)
         at Cryptography.main(Cryptography.java:265)
         at __SHELL4.run(__SHELL4.java:7)
         at bluej.runtime.ExecServer.vmSuspend(ExecServer.java:178)
         at bluej.runtime.ExecServer.main(ExecServer.java:143)
    here is my code to get the char array input:
        private char[] getPass () throws IOException{
            System.out.println("Input password (32 character max):");
            char[] holder = new char[maxChar];
            int holdspot=0;
            while ((holder[holdspot++] = (char) System.in.read()) != '\n') {};
            //Debug
            System.out.println("Holdspot is: "+holdspot);
            //End Debug
            char[] pass = new char[holdspot];
            System.arraycopy (holder, 0, pass, 0, holdspot);
            //clear our holder array
            for (int i=0; i<holder.length;i++){
                holder=0;
    //Debug
    System.out.print("Pass: ");
    for (int i=0; i<holdspot;i++){
    System.out.print(pass[i]);
    System.out.print("\n");
    System.out.print("Holder: ");
    for (int i=0; i<holder.length;i++){
    System.out.print(holder[i]);
    System.out.print("\n");
    //End Debug
    //Comment back in for final version, screen clear
    //System.out.flush();
    return (pass);
    here is my code at the point where the exception is thrown:
        private SecretKey createKey(PBEKeySpec keySpec)
        throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException{
            //Debug
            System.out.println("createKey Entered");
            char[] L = keySpec.getPassword();
            System.out.print("My keySpec value is: ");
             for (int i=0; i<L.length;i++){
                System.out.print(L);
    //End Debug
    SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
    SecretKey secKey = keyFac.generateSecret(keySpec);
    return (secKey);

    OK, got to Eclipse and reproduced the problem using your code.
    Something about the way you were reading your password bugged me. I changed your code a bit to the following:import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.security.InvalidKeyException;
    import java.security.NoSuchAlgorithmException;
    import java.security.spec.InvalidKeySpecException;
    import javax.crypto.SecretKey;
    import javax.crypto.SecretKeyFactory;
    import javax.crypto.spec.PBEKeySpec;
    public class PBETest {
      static final int MAX_CHAR = 32;
      private char[] getPass() throws IOException {
        System.out.print("Input password ("+MAX_CHAR+" character max):");
        String s = new BufferedReader(new InputStreamReader(System.in)).readLine();
        char[] holder = s.toCharArray();
        int holdspot = (s.length()>MAX_CHAR?MAX_CHAR:s.length());
        //End Debug
        char[] pass = new char[holdspot];
        System.arraycopy(holder, 0, pass, 0, holdspot);
        //clear our holder array
        for (int i = 0; i < holder.length; i++) {
          holder[i] = 0;
        //Debug
        System.out.print("Pass: ");
        for (int i = 0; i < holdspot; i++) {
          System.out.print(pass);
    System.out.print("\n");
    System.out.print("Holder: ");
    for (int i = 0; i < holder.length; i++) {
    System.out.print(holder[i]);
    System.out.print("\n");
    //End Debug
    //Comment back in for final version, screen clear
    //System.out.flush();
    return (pass);
    private SecretKey createKey(PBEKeySpec keySpec)
    throws NoSuchAlgorithmException, InvalidKeyException,
    InvalidKeySpecException {
    //Debug
    System.out.println("createKey Entered");
    char[] L = keySpec.getPassword();
    System.out.print("My keySpec value is: ");
    for (int i = 0; i < L.length; i++) {
    System.out.print(L[i]);
    //End Debug
    SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
    SecretKey secKey = keyFac.generateSecret(keySpec);
    return (secKey);
    public static void main(String[] args) {
    try {
    PBETest ptest = new PBETest();
    char[] pwd = ptest.getPass();
    PBEKeySpec spec = new PBEKeySpec(pwd);
    SecretKey sk = ptest.createKey(spec);
    } catch (Exception e) {
    e.printStackTrace();
    }And now it works.
    I don't know exactly why your "one char at a time from System.in" bugged me, and I don't know exactly why it didn't work - but that was the problem.
    Grant

  • Question about exceptions in function module GUI_DOWNLOAD

    To all,
    I add the function module 'GUI_DOWNLOAD' in the ABAP report program. After the user download the data to excel, the program also displays a report on the screen for print output.
    If the user keep the excel file open and tries to replace the file on download, the program gives an error message 'Access to file denied' and the program ends without displaying a report on the screen.
    Is there any way not to end the program even if download is failed?
    I would like the program displays a report after it gives an error message.
    So I am trying to use exceptions. But if I code to give messages, the programs ends as above. And if I just make exit when it happens, no error message and the program displays a report but the user don't know if the excel file was updated or not.
    Could anybody kindly let me know how to code exceptions and messages if it is possible the program works I hope.
    Thank you very much in advance.
    Best regards,
    Miki Komatsu

     I figured out how to do that.
      Thanks.
      Best regards,
      Miki

  • Question about Exception!

    class A
    public void f() throws Myexcption
    class B extends A
    public void f() throws [Myexception][devied exception from Myexception]
    Why B.f() can only throw less exceptions than A.f()?
    if A temp = new B();
    temp.f() will perform the B.f()'s defination. And if I defined B.f() as
    public void f() throws AnotherException
    throw AnotherException;
    It will has nothing to do with A.f().
    Why did the designer design the less exception throwwing rules?
    Thanks

    class MyFirstException extends Exception {}
    class MySecondException extends MyFirstException {}
    class A {
      public void f() throws MyFirstException { ... }
    class B extends A {
      public void f() throws MySecondException { ... }
    Why B.f() can only throw less exceptions than A.f()?The reason is one of decoupling. If you write code to the contract of A but are actually using an instance of B and the compiler allowed new exceptions to be thrown (not inheriting from the exceptions declared on the original contract) - you would have no way of knowing which other exceptions you must catch. Therefore by enforcing that an overriding method must throw only exceptions within the inheritance hierarchy of the original contract you can be certain to have caught all possible exceptions.
    EG
    A a = new B();
    try {
      a.f();
    } catch(MyFirstException e) { ... }--
    Talden

  • Question about Exception stack

    Hello,
    I get the following exception stack and it is not the first time that I get this "ClassName.<init>".
    What does the "init" mean?
    Thanks in advance,
    Balteo.
    oracle.xquery.XQException:  Too many arguments for function compare
         [java]      at oracle.xquery.PreparedXQuery.<init>(PreparedXQuery.java:63)
         [java]      at oracle.xquery.XQueryContext.prepareXQuery(XQueryContext.java:140)
         [java]      at com.agilience.sharenet.app.sgbdo.PPersistenceOracle.executeQuery(PPersistenceOracle.java:214)
         [java]      at com.agilience.sharenet.app.sgbdo.PPersistenceOracle.getAnonymousId(PPersistenceOracle.java:369)
         [java]      at com.agilience.sharenet.app.bl.persistence.PPersistenceModel.getAnonymousId(PPersistenceModel.java:112)

    When an exception occurs inside the constructor for the class, the stack trace refers to the constructor as <init>. <init> is the internal name that java uses to refer to constructors for a class.

  • Question on exception variable name

    A very simple question:
    In the following code
    public void compile() {
    ParseTree p;
    try {
    p = parse();
    p.toByteCode();
    catch (ParserException e1) { }
    catch (DumbCodeException e2) { }
    in the first catch clause, the variable name is e1 and e2 for the second catch clause. Can I use the same variable name e for both clauses?
    Edited by: Shibaryotaro on Aug 19, 2009 3:59 PM

    What happens when you try to?

  • Question on exception catching

    Runtime exceptions are not subject to the Catch or Specify Requirement
    I came across this line in the Java tutorial at http://java.sun.com/docs/books/tutorial/essential/exceptions/catchOrDeclare.html
    What did it mean?

    I understand some of what you write but I don't see
    how a compiler does not detect it. Sorry if I am
    sounding dumb. I never programmed before.Okay, more detailed explanation (which means I am in a good mood otherwise I don't like writing so much):
    Consider the following code.
    String s = null;
    // some code in between
    System.out.println(s.substring(0,1));What do you think will happen to this code? It will generate a NullPointerException when substring() is called on the String s unless something else is assigned to the s in between. Now this is something which can occur only when you execute your code.
    What I mean is, is there any way for the compiler to detect whether the value of the String variable s has changed? The answer is a plain no. It is not the job of the compiler to know that. So subsequently, a compiler cannot dictate to the programmer that a possible NullPointerException (NPE) needs to be handled because there is no way a compiler could be sure about a NPE in any case (unless it is too smart). There could be several other such exceptions which could occur. So that becomes an unchecked exception which is not checked by the compiler.
    Now coming to checked exception. If you are calling a method which already throws an exception as a known behaviour, the compiler is already aware. For example, a file read operation (I'm being lazy in typing code now) would throw an IOException which is defined as a part of the method signature. This makes the compiler aware of the possibility of getting an IOException. SO it checks to see if the programmer has taken care of the exception to make the code more fool-proof. This comes to be known as a checked exception.
    Does this make something clear? I hope so.

  • Simple questions about exceptions

    why use try catch with new File("filename") but not with x??

    ArrayIndexOutOfBoundsException is unchecked.
    IOException is checked.
    http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
    Here's a quick overview of exceptions:
    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.

  • Why do I need to catch this exception?

    Hello all
    This is a question about exception handling. I have to build a diary application that lets you save reminders on particular dates using xml. Just to make it a little tougher, I was not allowed to use the Calendar class. This is the code I wrote:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.text.*; 
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import java.io.*;     
    import org.w3c.dom.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;                                                                                                                                                                                                                         
    import static java.lang.Math.*;
    public class CalendarAssignment extends JFrame implements ActionListener
         int MonthLength [] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
         public JButton [] days = new JButton[43];
         private JLabel lbl, reminderlbl;
         private JPanel top, grid, remindercenter, reminderbottom;
         private JFrame reminderframe;
         private JTextField year1, reminderinput, dayno;
         private JComboBox months;
         private Container container;
         private JButton fetch, save, cancel;
         private Document doc;
         private File file;
         private Node node;
         private String year, month, day;
              public static void main( String[] args ) {
                   CalendarAssignment c = new CalendarAssignment( );
                   c.setSize( 400, 300 );
                   c.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                   c.show( );
              public CalendarAssignment( ) {
                   int CurrentYear, CurrentMonth;
                   String YearString, MonthString, Now;
                   Date today;
                   container = getContentPane( );
                   container.setLayout( new BorderLayout( ) );
                   SimpleDateFormat DateFormatter;
                   DateFormatter = new SimpleDateFormat( "MM.yyyy" );
                   today = new Date( );
                   Now = DateFormatter.format( today );
                   MonthString = Now.substring( 0,2 );
                   YearString = Now.substring( 3,7 );
                   CurrentMonth = Integer.valueOf( MonthString );
                   CurrentYear = Integer.valueOf( YearString );
                   top = new JPanel( );
                        String [] items = { "January", "February", "March", "April", "May", "June",
                                      "July", "August", "September", "October", "November",
                                      "December" };
                        months = new JComboBox( items );
                        months.setEditable( false );
                        months.setSelectedIndex( CurrentMonth - 1 );          
                        year1 = new JTextField( );
                        year1.setText( YearString );
                        year1.setEditable( true );
                        year1.setHorizontalAlignment( year1.CENTER );
                        fetch = new JButton( "Fetch Month" );
                        fetch.addActionListener( this );
                        top.setLayout( new GridLayout( 1, 3, 20, 0 ) );
                        top.add( months );
                        top.add( year1 );
                        top.add( fetch );
                   grid = new JPanel( );
                        grid.setLayout( new GridLayout( 7, 7, 0, 0 ) );
                        String [] week = { "Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun" };
                        for ( int a = 0; a < 7; a ++ ) {
                                  JLabel lbl = new JLabel( week[a], JLabel.CENTER );
                                  grid.add( lbl );
                        for ( int i = 0; i < 42; i ++ ) {
                                  days[i] = new JButton( );
                                  grid.add( days[i] );
                                  days.addActionListener( this );
                        DrawCalendar( CurrentMonth, CurrentYear );
                        container.add( top, BorderLayout.NORTH );
                        container.add( grid, BorderLayout.CENTER );
              private void DrawCalendar( int SelectMonth, int SelectYear ) {
                        int DisplayMonthLength, Buttons;
                        String ButtonID = "";
                        int OffSet = MonthStart( SelectMonth, SelectYear );
                        DisplayMonthLength = MonthLength [SelectMonth - 1];
                        if ( SelectMonth == 2 )
                             DisplayMonthLength += LeapYear( SelectYear );
                        for ( Buttons = 1; Buttons < 43; Buttons ++ ) {
                             if ( ( Buttons <= OffSet ) || ( Buttons > ( DisplayMonthLength + OffSet ) ) ) {
                                  ButtonID = "";
                                  days[Buttons-1].setEnabled( false );
                             else {
                                  ButtonID = Integer.toString( Buttons - OffSet );
                                  days[Buttons-1].setEnabled( true );
                        days[Buttons-1].setLabel( ButtonID );
                        grid.add( days[Buttons-1] );
              private int LeapYear( int year ) {
                        int FourHundred, OneHundred, Fourth;
                        FourHundred = year % 400;
                        OneHundred = year % 100;
                        Fourth = year % 4;
                        if( ( ( FourHundred == 0 ) ) || ( ( OneHundred != 0 ) && ( Fourth == 0 ) ) )
                             return ( 1 );
                        else
                             return ( 0 );
              private int MonthStart( int Month, int Year ) {
                        int OffSet, LastMonths, BeforeOrAfter, Years;
                        int AllDays = 0;
                        int YearDays = 365;
                        int YearMonths = 12;
                        BeforeOrAfter = Year - 2006;
                        Years = abs( BeforeOrAfter );
                        if( BeforeOrAfter != 0 )
                             BeforeOrAfter = BeforeOrAfter / Years;
                        switch( BeforeOrAfter ) {
                             case 1:
                                  for( int a = 2006; a < Year; a ++ ) {
                                       AllDays += YearDays + LeapYear( a );
                                  AllDays += LastMonthsCalc( Month, Year );
                             break;
                             case -1:
                                  for( int a = 2005; a > Year; a -- ) {
                                       AllDays += YearDays + LeapYear( a );
                                  for( LastMonths = YearMonths; LastMonths >= Month; LastMonths -- ) {
                                       AllDays += MonthLength[LastMonths - 1];
                                       if( LastMonths == 2 )
                                            AllDays += LeapYear( Year );
                             break;
                             default:
                                  if( Month > 1 )
                                       AllDays += ( LastMonthsCalc( Month, Year ) );
                        OffSet = AllDays % 7;
                        if( BeforeOrAfter ==( -1 ) )
                             return( 6 - OffSet );
                        else if( OffSet > 0 )
                             return( OffSet - 1 );
                        else
                             return( 6 );
              private int LastMonthsCalc( int Month, int Year ) {
                        int Counter;
                        int days = 0;
                        for( Counter = 1; Counter < Month; Counter ++ ) {
                             days += MonthLength[Counter - 1];
                             if( Counter == 2 )
                                  days += LeapYear( Year );
                        return( days );
              public void CreateReminder( String buttonID, String yearID, String monthID ) {
                        reminderframe = new JFrame( );
                        reminderlbl = new JLabel( );
                        reminderframe.setLayout( new GridLayout( 2, 1, 0, 0 ) );
                        remindercenter = new JPanel( );
                             reminderlbl = new JLabel( "Please type in reminder to be saved for " + buttonID + " " + monthID + " " + yearID + ":", JLabel.CENTER );
                             reminderinput = new JTextField( 30 );
                             reminderinput.setHorizontalAlignment( reminderinput.CENTER );
                             reminderinput.setEditable( true );
                             remindercenter.setLayout( new GridLayout( 2, 1, 0, 0 ) );
                             remindercenter.add( reminderlbl );
                             remindercenter.add( reminderinput );
                        reminderbottom = new JPanel( );
                             save = new JButton( "Save" );
                             save.addActionListener( this );
                             cancel = new JButton( "Cancel" );
                             cancel.addActionListener( this );
                             dayno = new JTextField( buttonID );
                             dayno.setEditable( false );
                             dayno.setEnabled( false );
                             dayno.show( false );
                             reminderbottom.setLayout( new FlowLayout( ) );
                             reminderbottom.add( save );
                             reminderbottom.add( cancel );
                             reminderbottom.add( dayno );
                        reminderframe.setSize( 500, 75 );
                        reminderframe.add( remindercenter );
                        reminderframe.add( reminderbottom );
                        reminderframe.pack( );
                        reminderframe.show( );
              public void SaveReminder( String dayID, String yearID, String monthID ) throws Exception {
                        file = new File( "Diary.xml" );
                        doc = DocumentBuilderFactory.newInstance( ).newDocumentBuilder( ).parse( file.toURL( ).toString( ) );
                        String year = yearID;
                        String month = monthID;
                        String day = dayID;
                        //System.out.println( year );
                        //System.out.println( month );
                        //System.out.println( day );
                        CreateEntry( doc.getDocumentElement( ) );
                        writeXmlFile( );
              public boolean CreateEntry( Node node ) {
                        Node searchNode;
                        searchNode = getYear( node );
                        if( searchNode == null ) {
                             Element newNode = doc.createElement( "Year" );
                             searchNode = node.appendChild( newNode );
                             newNode.setAttribute( "Id", year );
                        node = searchNode;
                        searchNode = getMonth( node );
                        if( searchNode == null ) {
                             Element newNode = doc.createElement( "Month" );
                             searchNode = node.appendChild( newNode );
                             newNode.setAttribute( "Id", month );
                        node = searchNode;
                        searchNode = getDay( node );
                        if( searchNode == null ) {
                             Element newNode = doc.createElement( "Day" );
                             searchNode = node.appendChild( newNode );
                             newNode.setAttribute( "Id", day );
                        node = searchNode;
                        String entry = reminderinput.getText( );
                        Node textNode = doc.createTextNode( entry );
                        node.appendChild( textNode );
                        return true;
              private Node getYear( Node node ) {
                        node = node.getFirstChild( );
                        while( node != null ) {
                             if(node.getNodeName( ).equals( "Year" ) && String.valueOf( node.getAttributes( ).item( 0 ).getNodeValue( ) ) == year )
                                  return node;
                                  node = node.getNextSibling( );                    
                        return null;
              private Node getMonth( Node node ) {
                        node = node.getFirstChild( );
                        while( node != null ) {
                             if( node.getNodeName( ).equals( "Month" ) && String.valueOf( node.getAttributes( ).item( 0 ).getNodeValue( ) ) == month )
                                  return node;
                                  node = node.getNextSibling( );                    
                        return null;
              private Node getDay( Node node ) {
                        node = node.getFirstChild( );
                        while( node != null ) {
                             if( node.getNodeName( ).equals( "Day" ) && String.valueOf( node.getAttributes( ).item( 0 ).getNodeValue( ) ) == day )
                                  return node;
                                  node = node.getNextSibling( );                    
                        return null;
              private void writeXmlFile( ) throws Exception {
                   Source source = new DOMSource( doc );
                        Result result = new StreamResult( file );
                   Transformer xformer = TransformerFactory.newInstance( ).newTransformer( );
                   xformer.setOutputProperty( OutputKeys.INDENT,"yes" );
                   xformer.setOutputProperty( OutputKeys.DOCTYPE_SYSTEM,"Diary.dtd" );
                   xformer.transform( source, result );
              public void actionPerformed( ActionEvent e ) {
                        String IDButton = e.getActionCommand( );
                        String IDYear = year1.getText( );
                        Object IDMonthObj = months.getSelectedItem( );
                        if( e.getSource( ) == fetch ) {
                             String YearText = year1.getText( );
                             int YearNumber = Integer.valueOf( YearText );
                             int MonthsIndex = months.getSelectedIndex( ) + 1;
                             DrawCalendar( MonthsIndex, YearNumber );
                        else if( e.getSource( ) == cancel ) {
                             reminderframe.hide( );
                        else if( e.getSource( ) == save ) {
                             String IDDay = dayno.getText( );
                             String IDMonth = String.valueOf( IDMonthObj );
                             SaveReminder( IDDay, IDYear, IDMonth );
                        else {
                             String IDMonth = String.valueOf( IDMonthObj );
                             Toolkit.getDefaultToolkit( ).beep( );
                             int n = JOptionPane.showConfirmDialog( null, "Set reminder on this date?", "Question", JOptionPane.YES_NO_OPTION );
                             if( n == JOptionPane.YES_OPTION ) {
                                  CreateReminder( IDButton, IDYear, IDMonth );
    If you compile it, you will realise that I get an error about exception handling. My lecturer gave me an example code of how to do the same thing without using a GUI:
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import java.io.*;
    import java.util.*;
    import org.w3c.dom.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    public class CallDOM
         Document doc;
         File file;
         Scanner input;
         int year, month, day;
         String currentYear, currentMonth;
         public static void main(String args[]) throws Exception
              CallDOM cd=new CallDOM();          
         CallDOM() throws Exception
              file=new File("Diary.xml");
              //create DOM from file
              doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file.toURL().toString());
              input=new Scanner(System.in);
              System.out.println("1) Create entry");
              System.out.println("2) Read entry");
              System.out.println("3) Show Diary");
              System.out.println("4) Quit");
              int choice=input.nextInt();
              while(choice!=4)
                   switch(choice)
                        case 1: GetDate();CreateEntry(doc.getDocumentElement());break;
                        case 2: GetDate();ReadEntry(doc.getDocumentElement());break;
                        case 3: ShowDiary(doc.getDocumentElement());
                   System.out.println("1) Create entry");
                   System.out.println("2) Read entry");
                   System.out.println("3) Show Diary");
                   System.out.println("4) Quit");
                   choice=input.nextInt();
              writeXmlFile();
         public void GetDate()
              System.out.println("Enter date (dd mm yyyy)");
              day=input.nextInt();
              month=input.nextInt();
              year=input.nextInt();
         public boolean ReadEntry(Node node)
              node = getYear(node);
              if(node==null) return false;
              node = getMonth(node);
              if(node==null) return false;
              node = getDay(node);
              if(node==null) return false;
              node = node.getFirstChild();
              while(node!=null)
                   System.out.println(node.getNodeValue().trim());     
                   node=node.getNextSibling();
              return true;               
         public boolean CreateEntry(Node node)
              Node searchNode;
              searchNode = getYear(node);
              if(searchNode==null)
                   Element newNode = doc.createElement("Year");
                   searchNode = node.appendChild(newNode);
                   newNode.setAttribute("Id",Integer.toString(year));
              node = searchNode;
              searchNode = getMonth(node);
              if(searchNode==null)
                   Element newNode = doc.createElement("Month");
                   searchNode = node.appendChild(newNode);
                   newNode.setAttribute("Id",Integer.toString(month));
              node = searchNode;
              searchNode = getDay(node);
              if(searchNode==null)
                   Element newNode = doc.createElement("Day");
                   searchNode = node.appendChild(newNode);
                   newNode.setAttribute("Id",Integer.toString(day));
              node = searchNode;
              System.out.println("Enter Text");
              String entry=input.next();
              entry+=input.nextLine();
              Node textNode = doc.createTextNode(entry);
              node.appendChild(textNode);
              return true;               
         public void ShowDiary(Node node)
              Stack<Node> stack=new Stack<Node>();
              Node child;
              stack.push(node);
              while(!stack.empty())
                   node = stack.pop();
                   if(ProcessNode(node))
                        child = node.getLastChild();
                        while(child!=null)
                             stack.push(child);
                             child = child.getPreviousSibling();
         private boolean ProcessNode(Node node)
              if(node.getNodeName().equals("Year"))
                   currentYear=node.getAttributes().item(0).getNodeValue();
              if(node.getNodeName().equals("Month"))
                   currentMonth=node.getAttributes().item(0).getNodeValue();
              if(node.getNodeName().equals("Day"))
                   System.out.print(node.getAttributes().item(0).getNodeValue()+"/"+
                                            currentMonth+"/"+currentYear+": ");
                   node=node.getFirstChild();
                   while(node!=null)
                        System.out.println(node.getNodeValue().trim());
                        node=node.getNextSibling();
                   return false;
              return true;               
         private Node getYear(Node node)
              node=node.getFirstChild();
              while(node!=null)
                   if(node.getNodeName().equals("Year")
                        && Integer.valueOf(node.getAttributes().item(0).getNodeValue())==year)
                             return node;
                   node = node.getNextSibling();                    
              return null;
         private Node getMonth(Node node)
              node=node.getFirstChild();
              while(node!=null)
                   if(node.getNodeName().equals("Month")
                        && Integer.valueOf(node.getAttributes().item(0).getNodeValue())==month)
                        return node;
                   node = node.getNextSibling();                    
              return null;
         private Node getDay(Node node)
              node=node.getFirstChild();
              while(node!=null)
                   if(node.getNodeName().equals("Day")
                        && Integer.valueOf(node.getAttributes().item(0).getNodeValue())==day)
                        return node;
                   node = node.getNextSibling();                    
              return null;
         private void writeXmlFile() throws Exception
            Source source = new DOMSource(doc);
            Result result = new StreamResult(file);
            Transformer xformer = TransformerFactory.newInstance().newTransformer();
            xformer.setOutputProperty(OutputKeys.INDENT,"yes");
            xformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"Diary.dtd");
            xformer.transform(source, result);
    }My question is, why does the exceptions in the example code not need to be caught? And why do I have to catch the exceptions in my code? Several exceptions are thrown in the example code, but there is no catch statement.
    Thanks for any advice!!

    Since your question didn't come with any relevant details, and since you have huge steaming piles of irrelevant code, all I can give is a general answer to "Why do I need to catch this exception?"
    [url http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html]Exception tutorial at http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
    Here's a quick overview of exceptions:
    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.

  • Exception not working

    create procedure name emp_test as
    cursor c1 is select * from emp where deptno=10;
    begin
    for i in c1 loop
    begin
              insert into emp1(col1,col2,col3)value(i.col1,i.col2..........);
    exception
    when no_data_fund then
    dbms_output.put_line( 'no data found from thhis deptno' || i.deptno);
    end;
    end loop;
    end;
    my question is, exception is not working when no datafound in my cursor.
    Please help me out in this regard.
    thanks in advance
    Dharma.

    You are using a for loop, in case no data is found by the cursor c1, the statement in the for loop is not executed so there is no question of exception.
    Try the below code, the exception will be raised -
    declare
    v_cnt number;
    begin
    select count(*) into v_cnt from emp where deptno=-999;
    insert into emp1(col1,col2,col3)value(i.col1,i.col2..........);
    exception
    when no_data_found then
    dbms_output.put_line( 'no data found from thhis deptno' );
    end;

  • Using Linq Query in our program error is thrown :Exception has been thrown by the target of an invocation.

    Hi All,
      I am writing the below linq query to fetch the record from the database ,
    var individualres = (from c in orgContext.CreateQuery("contact")
                                                 join a in orgContext.CreateQuery("annotation")
                                                      on c["contactid"] equals a["objectid"]
                                                 where (bool)a["isdocument"] == true && a["objectid"] == r.GUID &&
    a["filename"] != null
                                                 select new
                                                     FirstName = c["firstname"],
                                                     LastName = c["lastname"],              
                                                     CreatedDate=a["createdon"],
                                                     DocumentBody = (a["documentbody"] == null) ? "" : a["documentbody"],
                                                     GUID = c["contactid"],
                                                     FileName = a["filename"],
                                                     WorkStatus = (c["new_workstatus"] == null) ? "" : c["new_workstatus"],
                                                     Rank = (c["new_rank"] == null) ? "" : c["new_rank"],
                                                     State = (c["address1_stateorprovince"] == null) ? "" : c["address1_stateorprovince"],
                                                     City = (c["address1_city"] == null) ? "" : c["address1_city"]
    But it is throwing the error   Exception has been thrown by the target of an invocation.
    if this error is related to null values into the columns , then i am handling those by using the 
    ternary operator.
    Can anybody help me out for this issue.
    thanks in advance.

    Hello EmpAnsar,
    >>But it is throwing the error   Exception has been thrown by the target of an invocation.
    From your LINQ query, it is hard to tell what the caused reason is since we do not have your exact tables and data. My suggestion is that you could narrow this issue by reducing items you want to fetch, for example, you could firstly write a sample query
    without where clause and select new syntax as:
    var individualres = (from c in orgContext.CreateQuery("contact")
    join a in orgContext.CreateQuery("annotation")
    on c["contactid"] equals a["objectid"]
    select c).ToList();
    To check if it would work, if so, you could add these filters and items you want step by step until reproducing this issue, this would help locate the root reason.
    Update:
    For this exception, i found some related threads which might be helpful to you:
    http://stackoverflow.com/questions/11809530/linq-and-exception-has-been-thrown-by-the-target-of-an-invocation
    http://stackoverflow.com/questions/4074058/exception-raised-when-using-a-linq-query-with-entity-framework
    http://stackoverflow.com/questions/7674105/linq-aggregate-produces-error-exception-has-been-thrown-by-the-target-of-an-in
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Change BI 7 WAD exception symbol

    Dear All,
    I have a question regarding exception symbol in BI 7 WAD. we can change the exception from color to image(symbol). the question is can we change the symbol? the default is just an arrow up, down and across. I want to change with something else. Thanks in advance.
    Regards,
    Tienus.

    Dear Michael,
    Raj havent sent me any document for the solution, I am still waiting for the document.
    I try to use the css in the header of the html in WAD and somehow it works, but doesnt give us any flexibility. just try to put the background image on the css class which the exception needed.

Maybe you are looking for

  • Revision level not appearing in material tab of purchase order

    hi I have matained revision level in material master but it is not appearing in material tab of purchase order and print preview of purchase order regards Badari

  • Icon_history

    hi i need to add icon_history symbol in the alv grid could you please help in this <b><REMOVED BY MODERATOR></b> Message was edited by:         Alvaro Tejada Galindo

  • Billing charges appear double

    have double freedom, phone and hi speed internet, and it looks like i am being billed twice what i think i signed up for. has anybody fiqured out how to fiqure out the bill?  basic, non basic, non payment of non basic will not result in disconnection

  • .search button doesnt work/react

    ''dupe of https://support.mozilla.org/en-US/questions/947987'' search button in homepage doesent work after updating, after restarting ff with addons turned off problem is still there.

  • CMOS vs CCD

    The new Sony Cameras are all CMOS including the latest replacement for the Z1. Question: is it not true that 3CCD is still better than CMOS? I'm hesitating between the Z1/G1 and the new 3 CMOS Sony Camera.