Do I always need to use try/catch? [ newbie ]

Hi,
I have a method called methodOne that throws ExceptionXXX, and another method called methodTwo that uses methodOne and also throws ExceptionXXX.
public static methodOne() throws ExceptionXXX
Does methodTwo need to use try/catch to catch ExceptionXXX from methodOne, ( like the following code )
public static methodTwo() throws ExceptionXXX
try
methodOne();
catch( ExceptionXXX theException )
throw new ExceptionXXX;
or it isn't necessary ( like this code )?
public static methodTwo() throws ExceptionXXX
methodOne();
Thanks for the help,
Andre

Hi,
if you call a mthod w/ a throws declaration you hace two possibilities:
1. catch the Exception
2. pass the Exception by adding a throws declaration to the calling method
So, in your case the second example is a valid way to handle the Exception.
Also Andre

Similar Messages

  • How to use Try Catch Block in ABAP Like JAVA

    Hi Experts,
       I am using BAPI to post MIGO in one of my application. If the MIGO is successfully gets posted then BAPI returns no message, but if there is some error in posting then it returns an error message. Now I want to print that error message in catch block by calling method RAISE_ERROR_MESSAGE. How to use try catch block in ABAP. Please suggest with example.
    Thanks and Regards.
    Vaibhav Tiwari.

    Hi Vaibhav
    You may not catch exceptions returned by function module using try endtry block.
    It works well with the exception returned by methods.
    In case of function modules or BAPI what u can do is to check sy-subrc returned and give message accordingly. If it returns a structure like bapireturn then display message returned.
    in case of exception returned by a method,  do it like this...
    data: excep type cx_root.
    data: v_str type string.
    try.
    *any method call or division by zero (for ex)
    catch cx_root into excep.
    endtry.
    if  excep is not initial.
    CALL METHOD   excep->if_message~get_text
      receiving
        RESULT = v_str.
    endif.
    *display the value returned in v_str on screen

  • Error when using try catch inside oledb command to run stored procedure

    Hi,
    i'm using the below command to run some jobs  using OLEDB Command
    exec sp_start_job @job_name =?
    and it runs successfully
    when i put this code inside try catch block as below , it generates error and don't accept it
    begin try
    exec sp_start_job @job_name =?
    end try
    begin catch
    end catch
    the error message is "Syntax error, PErmission vaiolation or other nonspecific error"
    do you know is there any problem using TRY catch insdie OLEDB command ?
    Thanks ,
    Ahmed Salah

    Hi Ahmed,
    According to your description, if an error raised that fails the package, then you want the package to continue execute.
    To achieve this requirement, we can use Integration Services (SSIS) Event Handlers that we can create custom event handlers for an OnError event when an error occurs to continue processing rest of the package. For more details, please refer
    to the following blog:
    http://visakhm.blogspot.in/2013/03/error-handling-in-ssis-loops.html
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How do I use try/catch so that it loops until proper input is put in?

    So I have a specific thing that I am asking for (double)... if user inputs letters instead i do try/catch... how do I have it loop until user puts in proper stuff?

    i think i might have figured it out...
              String first = JOptionPane.showInputDialog("Enter the first number");
              while(num1 != double || num1 != int){
              try{
              num1 = Double.parseDouble(first);
              catch (NumberFormatException e){
                   String first = JOptionPane.showInputDialog("Enter the first number");
              }now i need to figure out how to make
    num1 != double || num1 != intpart work..

  • How to deal exception using try{}catch{}

    I don't know which is a good way from catch a exception and throw a exception,
    I means that how to use exception in java,catch ? throw?

    Presumably you are not asking the same thing as here...
    http://forum.java.sun.com/thread.jsp?thread=461313&forum=9&message=2114037
    You catch an exception with code that looks like the following...
        try
          String s = null;
          int i = s.length();  // This throws an exception
        catch(NullPointerException e)
          // Do something
    You throw an exception with the following...
        if (<some condition>)
           throw new Exception("Something bad happened");

  • Need help with try catch

    i have a catch block as follows
    catch (FileNotFoundException fnfe) {
                   System.out.println ("Library of Leng could not find a needed file.");
                   System.out.println (fnfe.printStackTrace());
                   JOptionPane.showMessageDialog (desktop, "File not found.", "ERROR", JOptionPane.WARNING_MESSAGE);
    but when i compile it says that void is not allowed and highlights the line:
    System.out.println (fnfe.printStackTrace());
    but according to the api this is a valid method.
    am i not reading this right or is java just fscked up?

    "am i not reading this right or is java just fscked up? "
    The problem is ALWAYS between the chair and the monitor. There are way to many coders working with and on java for such a mistake to (still) be present.
    In this case a "RTFM" was a proper response, because the javadocs clearly state that printStackTrace() returns void.

  • Help regarding try catch!

    In the following code, when the exception occurs at b, the control goes to the catch block! however, though the values for c, d are perfect, they are never reached!
    Is there anyway to make the control return to where the exception was thrown & continue from there?
    int a=0,b=0,c=0,d=0,
    try {
              a = Integer.parseInt("11");
              b = Integer.parseInt("aa");
              c = Integer.parseInt("33");
              d = Integer.parseInt("44");          
         } catch(Exception ex) {
              System.out.println("Except occured: " + ex);          
         }

    No.
    If you want that other code to execute it would need a seperate try/catch block OR to go in the finally block. Whatever you feel.

  • Doubt try/catch/finally

    Hi all
    Say i have following program:
    try {
    line1.   functioncall()
    line2.    .....
    line3.    .....
    catch(..) {
    print error
    finally{
    System.out.println("In finally");
    }As per my understanding if there is some error in try block , then control will skip to catch and then to finally.
    And other way, if there is no error then all lines in try block will be executed and control has to go to finally block.
    And i see that there is no error (i have used try catch inside line1 function call also)
    Now I am facing this problem.
    In try block, line 1 is executed and getting into finally and there is also no error so it has skipped catch block. And in try block line2 and line 3 are skipped.
    Can anybody tell me why is it so.
    thanks
    Ravi

    What might be the problem?Sunspots. Not enough fiber. Government conspiracy.
    These are just guesses, which is all we can do unless you read and obey the following:
    Please post a short, concise, executable example of what you're trying to do. This does not have to be the actual code you are using. Write a small example that demonstrates your intent, and only that. Wrap the code in a class and give it a main method that runs it - if we can just copy and paste the code into a text file, compile it and run it without any changes, then we can be sure that we haven't made incorrect assumptions about how you are using it.
    Post your code between [code] and [/code] tags. Cut and paste the code, rather than re-typing it (re-typing often introduces subtle errors that make your problem difficult to troubleshoot). Please preview your post when posting code.

  • Try/catching errors occuring in synchronous event handlers

    Hi,
    I know that using try/catch in flash player it is possible to catch only synchronous errors, but recently I ran into code in our application which I strongly believe is synchronous but it behaves as if it wasn't.
    In example below I create event listener and inside try/catch I dispatch event. Handler function throws error. Executing code stops when error is thrown, so message "after throwing error" won't be logged, but try/catch block catches nothing and code executes as if nothing happened after event dispatch.
    Dispatching event on element executes handler method immediately so it is synchronous execution. Event call stack which is displayed in debug versions of flash player, shows every function from creation of class to execution of handler.
    Generally flash applications relays heavily on events and in my case it caused ours users projects to be irreversibly corrupted, because of this continuing to work after error, which I even can't properly detect and handle, cause it's going throught 5 or more event handlers and adding try/catch to each handler would create enormous chaos in my code. So my question is why does flash player behaves like this? Are there any ways to tell compiled SWF file to treat such cases as synchronous calls, f.e. compilation parameters?
    package
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.EventDispatcher;
        import flash.text.TextField;
        public class TestApp extends Sprite
            public var cTextField:TextField;
            public function TestApp()
                cTextField = new TextField();
                cTextField.width = 300;
                cTextField.height = 200;
                addChild(cTextField);
                onAppCreated();
            protected function onAppCreated():void
                var eventName:String = "my_event";
                var caughtError:Boolean = false;
                var dispatcher:EventDispatcher = new EventDispatcher();
                dispatcher.addEventListener(eventName, handler);
                try
                    dispatcher.dispatchEvent(new Event(eventName));
                } catch (error:Error)
                    caughtError = true;
                cTextField.text += caughtError ? "caught error\n" : "error wasn't caught\n";
            protected function handler(event:Event):void
                cTextField.text += "before throwing error\n";
                throw new Error("throw error");
                cTextField.text += "after throwing error\n";

    Okay, nobody bit.  Sorry. 
    The only way to really figure out what is going on is to look at a running example with a C++ debugger.  I'm particularly curious about whether this problem happens in a specific browser/os combination (we may be working around a quirk of that platform), or if it's something that happens everywhere.
    The most effective way to proceed is going to be to file a bug with a simplified, executable example (source and compiled SWF, ideally) that demonstrates the problem.  This will help me route the bug to a developer and get you an answer in the shortest time possible. 
    You can file a bug here:
    http://bugbase.adobe.com/
    If you reply here with the bug number, I'll get it assigned to an engineer.
    Thanks!

  • How to know if a UDF form is opened else then using a TRY CATCH ?

    I'm looking for any way to find out if the UDF form is visible
    else then trying to open it in a try catch and if it's not sending a key.  This if very ugly, slow and not really my kind.
    I tried to iterate through all the forms in SBO_Application.Forms but it's not there.  All I see is the main form
    I just need to make sure the UDF form is visible when Inventory form is loaded so I can put a value in one of the UDF
    If there's a better way I'm buying it

    Hi Marc,
    Rather than putting your data in the UDF in the UDF side form, you can add a control to the main form (during the load event of the form) and bind this to the UDF through the DBDataSource that is already available on the main form. This means that you don't need to worry about whether the UDF form is open or not because you can always read or write to your UDF data from the main form.
    Alternatively, the UDF form TypeEx property is always the same as the main form but with a minus sign in front. Therefore, if you know the TypeEx and FormTypeCount of the main form then you can use the GetForm method of the Application object to get the UDF form.
    oForm = _sboApp.Forms.GetForm("-" + oMainForm.TypeEx, oMainForm.TypeCount);
    You'd still need a try/catch around this and if it raises an error then activate the 6913 menu to open the UDF form.
    Kind Regards,
    Owen

  • When I try to upgrade and install to iOS 5.1, error message prompt "operation stop running". I have tried several time but failed. Also, would like to know why always need to have wifi access in order to upgrade the version of iPad iOS, why not 3G ?

    When I try to upgrade and install to iOS 5.1, error message prompt "operation stop running". I have tried several time but failed. Also, would like to know why always need to have wifi access in order to upgrade the version of iPad iOS, what is the purpose of 3G then? This is really nonsense using wifi + 3G iPad. need help ! Thanks.

    The file is too large to download via 3G. There is a 20MB limit with 3G. The purpose of having 3G is that you have internet access everywhere and do not need to be near a WiFi hotspot or network.
    Not every single thing that you do every single minute of the day on the iPad involves downloading files larger than 20MB. You can surf the internet all day long sitting out in a park somewhere with 3G - but not with a WiFi only iPad - unless you use a hotspot with it.
    Try turning off your firewall and anti virus software while you try to download the iOS update.

  • Need HELP with finally() in nested try-catch

    hi,
    i am having trouble with deadlock and wondering if its due to an incorrect use of finally nested within multiple try catch blocks.
    is the inner finally() required, will the outer one get executed, or will the two finally() statements get executed...??
    the deadlock happens very infrequently to accurately test.
    try {
         try {
         catch (InterruptedException e) {
              return;
    catch {
    finally {
         //will this be executed be executed by the inner throw statement
    }or is an inner finally required
    try {
         try {
         catch (InterruptedException e) {
              return;
         //this finally is NEW....is it needed!
         finally {
              //will this be executed. will both get executed
    catch {
    finally {
         //will this be executed also, or completely ignored if exception throw from inner try/catch
    }

    inner/outer, which one is executed first?
    more info pls.I mean, really. How hard is it to find out for yourself?
    public class TestFinally {
        public static void main(String[] args) {
            try {
                try {
                    throw new RuntimeException("Whatever");
                } finally {
                    System.out.println("Inner finally");
            } finally {
                System.out.println("Outer finally");
    }I'll leave it to your imagination as to how to modify this class to confirm the answers to your original question.

  • I have always paid for apps with a credit card and now need to use an app store card but I can't get past the point where it keeps wanting my credit card updated.  And can't used the app card number.  Any advice???

    I have always paid for apps with a credit card and now need to use an app store card but I can't get past the point where it keeps wanting my credit card updated.  And can't used the app card number.  Any advice???

    I do NOT like using my credit card if I don't have to, and I went out of my way to go buy an Apple gift card, which I successfully redeemed into my Apple account. However, when I use the Apple "Cards" app, it will not let me use anything other than my credit card. I tried purchasing a card, hopefulling it would come out of my Apple store balance, but no such luck -- it came out of my credit card.
    Apple is becoming more like Microsoft every day.

  • Ive just signed up for the adobe photoshop pack, i use a mac, when i click download, nothing is happening..  Am I doing something wrong?? When I try and open the software I already had from trial it says its expired,  or i need to use a serial number... H

    Ive just signed up for the adobe photoshop pack, i use a mac, when i click download, nothing is happening..  Am I doing something wrong?? When I try and open the software I already had from trial it says its expired,  or i need to use a serial number... HELP Anyone else experienced this?

    If there is an option to "license this software", and it takes you to a sign-in page with username and password (not a serial number) - then just go ahead and sign in.
    If it insists on a serial number you need to uninstall the trial. Then try to download again.

  • Tried to use Iphoto and was told I needed upgrade. Try to install upgrade . Upgrade should take an hour if photo library is large. It's now close to three hours and still upgrading.  Can't use Iphoto and don't want to stop if still upgrading...3hours??

    Tried to use Iphoto and was told I needed upgrade. Try to install upgrade . Upgrade should take an hour if photo library is large. It's now close to three hours and still upgrading.  Can't use Iphoto and don't want to stop if still upgrading...3hours??

    You are on Windows 2000, you do not have a "Firefox" button, and should consider yourself to be fortunate in that you still have menus and don't have to do anything to get the menus back instead of the "Firefox" button. (The same applies to Windows XP users).
    Use the "File" menu to get to Import. You are not on Windows 7 or Vista, and don't have to put up with the nonsense added for Aero.
    If you want the "Firefox" button you can get it with View -> toolbars -> (uncheck) Menu Bar. The menu bar and the "Firefox" button were supposed to be mutually exclusive (which is impossible in some cases without being incompatible).
    Once you are using the "Firefox" button ...
    Use the "Alt" key to view the menu bar (temporarily) containing File, Edit, View, History, Bookmarks, Tools, and Help. On Windows 7 and Vista, the menu bar was hidden by default in Firefox 4 and above. These menu items are more or less available under the "Firefox" button which has the most used of the built-in Firefox menu items available in a different format.
    To get back to having menus again. "Firefox" button -> Options (second column) -> (check) Menu Bar
    You can make '''Firefox 7.0.1''' look like Firefox 3.6.*, see numbered '''items 1-10''' in the following topic [http://dmcritchie.mvps.org/firefox/firefox-problems.htm#fx4interface Fix Firefox 4.0 toolbar user interface, problems (Make Firefox 4.0 thru 8.0, look like 3.6)]. ''Whether or not you make changes, you should be aware of what has changed and what you have to do to use changed or missing features.''
    * http://dmcritchie.mvps.org/firefox/firefox-problems.htm#fx4interface

Maybe you are looking for

  • How do i get more memory installed on my macbook air

    How do i get more memory installed on my macbook air

  • DVI to VGA or DVI to Component?

    I just purchased a new 26" LCD tv. I've notice whenever I connect anything to it via VGA (e.g: Macbook Pro, iMac, or my Xbox360) the colors are somewhat washed out, there's a great deal of pixilation, as well as poor black levels. Yet when I watch th

  • How to select Subpartition name in a Select query?

    Hi, I have a table that is partitioned on date range and subpartitioned based on and ID list. Lets assume the table name is something like: MY_TABLE The partition name would look like: P_20110126160527 The subpartition list is as follows: GB, IN, AU,

  • MRM_INVOICE_DOCUMENT_POST

    Hi Experts, when we are running /cockpit/1 T-code.we are getting FI and MM documents.all are in parked status. for FI documents we check the documents in FBV2 .We can able to see the documents. but for MM documents,we checked in MIR4.then got the mes

  • PR PO Approval Question

    Hello Experts - We have a business requirement from our current client and nee dyou expert advice on how to map build this in system: 1. PR Created through network or work order and moving average price was copied from material master 2. PR went thro