How to restarting code that caused exception?

Hello all,
Suppose we have handled an exception in a catch block. Is there anyway we can restart the line that caused the exception?
For example:
try {
System.out.println("here"); // this line should be executed only once
a = b / c // we want to execute this line again if an exception occurs
catch(Exception e) {
c = 0.01;
// OK, we have now corrected the problem (division by 0). How can we
// restart the offending line (a = b / c) in the try block?
Thanks for any help!
-Kamran
[email protected]

You can put the offending portion of code in its own block:System.out.println("here");
try {
         a = b / c // we want to execute this line again if an exception occurs
catch(Exception e) {
    a = b / 0.01;
System.out.println("and here");And possibly eliminate the try-catch mechanism completely:System.out.println("here");
c = (c == 0) ? 0.01 : c;
a = b / c;
System.out.println("and here");

Similar Messages

  • Simple AS3 code that causes 10.2 to crash

    Very simple code that causes flash 10.2 to crash on all platforms.
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="300" minHeight="200">
         <fx:Script>
              <![CDATA[
                   import mx.controls.Alert;
                   private function crash(type:int, ...additionalArgs):void {
                        var msg:String;
                        switch (type) {
                             case 1: msg = "Crashes!"; break;
                             case 2: msg = additionalArgs[0]; break;
                        Alert.show("Crash : " + msg);
                   private function notCrash(type:int, ...additionalArgs):void {
                        // Does nothing at all, but stops the crash....
                        if (additionalArgs) {}
                        var msg:String;
                        switch (type) {
                             case 1:msg = "Not crash"; break;
                             case 2: msg = additionalArgs[0]; break;
                        Alert.show("NotCrash : " + msg);
              ]]>
         </fx:Script>
         <s:Button label="Does not crash flash" click="notCrash(2,'value')" x="10" y="10"/><s:Button label="Crash flash" click="crash(2,'value')" x="150" y="10"/>
    </s:Application>

    hkudo wrote:
    mike_brewer,
    Thank you for reporting the bug. We will take a look at this bug asap.
    thanks,
    Hitomi
    FP/AIR team
    Hi Hitomi
    Thank you! Finally someone is looking into this.
    I have also submitted a bug report on your site about this issues.
    Currently for the developers there is a simple workaround; which is to wrap the switch statement that uses a rest parameter in a try/catch. This
    prevents the crash even though the catch statement is reached!
    I have also have another forum post that goes into more detail about this :
    http://forums.adobe.com/thread/795395?tstart=0
    Regards Michael

  • TSQL code that causes table data to be deleted rather than fail with a compilation error

    Afternoon,
    I recently did this by accident and it felt as though it should have failed with a compilation error rather than run
    A query of the form
    delete from jobs
    where id in
    select id from calibrations
    will delete all rows in the jobs table when the id column exists in the jobs table, but not the calibrations table. This should fail with a compilation error.
    the following sql can be used to generate a test database to show the problem
    USE [test]
    GO
    /****** Object:  Table [dbo].[calibrations]    Script Date: 28/11/2014 13:32:59 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[calibrations](
        [JobId] [int] NULL,
        [textfield] [nvarchar](50) NULL
    ) ON [PRIMARY]
    GO
    /****** Object:  Table [dbo].[jobs]    Script Date: 28/11/2014 13:32:59 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[jobs](
        [Id] [int] NOT NULL,
        [Name] [nchar](10) NULL
    ) ON [PRIMARY]
    GO
    INSERT [dbo].[calibrations] ([JobId], [textfield]) VALUES (1, N'something')
    GO
    INSERT [dbo].[jobs] ([Id], [Name]) VALUES (1, N'a         ')
    GO
    INSERT [dbo].[jobs] ([Id], [Name]) VALUES (2, N'b         ')
    GO
    INSERT [dbo].[jobs] ([Id], [Name]) VALUES (3, N'c         ')
    GO
    INSERT [dbo].[jobs] ([Id], [Name]) VALUES (4, N'd         ')
    GO
    INSERT [dbo].[jobs] ([Id], [Name]) VALUES (5, N'e         ')
    GO
    INSERT [dbo].[jobs] ([Id], [Name]) VALUES (6, N'f         ')
    GO
    Simon
    simon

    will delete all rows in the jobs table when the id column exists in the jobs table,
    but not the calibrations table. This should fail with a compilation error.
    Hello Simon,
    That's a bug in your T-SQL Statement, not in SQL Server. The Statement as it is valid and column "id" exists, so why should it fail on compilation?
    And that is the reason why we always should use full qualified object name, e.g. like
    delete from jobs AS J
    where J.id in
    select SUB.id from calibrations AS SUB
    and this Statement should fail on compilation.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Code causing exceptions at its own sweet time and place

    import java.lang.*;
    class newthread implements Runnable
         Thread t;
         int click=0;
         public volatile boolean running=true;
         newthread(int p)
              t=new Thread(this);
              t.setPriority(p);
         void start()
              t.start();
         public void run()
              while(running)
                   click++;
         void start1()
              running=true;
         void stop()
              running=false;     
    class threadpriority2
         public static void main(String argv[])
              newthread ob1=new newthread(Thread.NORM_PRIORITY+2);
              newthread ob2=new newthread(Thread.NORM_PRIORITY-2);
              ob1.start();
              ob2.start();
              try
                   Thread.sleep(5000);
              catch(Exception e)
                   System.out.println("error detected:"+e);
              System.out.println("first one:"+ob1.click);
              System.out.println("first one:"+ob2.click);
              System.out.println("the priority of ob1 is:"+ob1.t.getPriority());
              System.out.println("the priority of ob2 is:"+ob2.t.getPriority());
              ob1.stop();
              ob2.stop();
              ob2.t.setPriority(Thread.NORM_PRIORITY+3);      
              ob1.t.setPriority(Thread.NORM_PRIORITY-3);
              ob1.start1();
              ob2.start1();
              ob1.start();
              ob2.start();
              System.out.println("the priority of ob1 is:"+ob1.t.getPriority());
              System.out.println("the priority of ob2 is:"+ob2.t.getPriority());
              try
                   Thread.sleep(5000);
              catch(Exception e)
                   System.out.println("error detected:"+e);
              ob1.stop();
              ob2.stop();
              System.out.println("first one:"+ob1.click);
              System.out.println("first one:"+ob2.click);
    errors during runtime:
    Exception in thread "main" java.lang.IllegalThreadStateException
    at java.lang.Thread.start(Unknown Source)
    at newthread.start(threadpriority2.java:17)
    at threadpriority2.main(threadpriority2.java:77)
    when i run this code it causes exceptions at its own sweet locations when i run it separately.if once it displays some valid input it would then be followed by the exception
    next time if i run it it will throw exception as soon as i run it at the very start without displaying even an iota of valid data like the previous case
    is ti because the os is placing restrictions on the threads growth or something else.incase there is an error in my code it should atleast pop up the exceptions at one particular loaction in the output and not give different outputs

    1) When you post code, please use and tags as described in Formatting tips on the message entry page. It makes it much easier to read.
    wasnt aware of it.will keep it in mind i post nexttime.sorry for the inconvenience[\b]
    3) You have multiple threads, right? The scheduling of which thread gets how much CPU time when is not subject to your control or prediction, so of course you'll see different timings in subsequent runnings of the same code.[b]actually the problem is not with multiple threads showing different times.whats happening is that exceptions are being thrown randomly at runtime.once when i ran it the exception was displayed at the very beginning of the output and the program snapped.next when i ran it first some output which was slated to be displayed got displayed and then the exceptions appeared in the output.now if the exceptions are thrown at the very beginning its obvious theres some problem at the background coz in the second case that never happened[\b]
    i guess the formatting tips have taken effect[:D]

  • Code that handles a set of questions from database and place it on JSP

    Hi,
    How to write a code that handles a set of Quiz questions from database and place it on JSP page..
    Thanks in advance
    Haritha

    975033 wrote:
    Hi,
    I hav got the answer from you r previous link, but not completly. I need help regarding on how to do code that handles a set of questions from database and place it on JSP.
    Any help is highly appreciated.Yes but what kind of help do you expect to get? What kind of help do you think is possible through something as cold and distant as a forum, where you clearly require personal guidance and tutoring?
    If you are going to answer "example code", I should warn you that the answers are not going to be to your liking.

  • [svn:fx-trunk] 12077: Although Spark RichText does not support link formats , modifying compiled FXG to not generate ActionScript code that will cause compile time exceptions .

    Revision: 12077
    Revision: 12077
    Author:   [email protected]
    Date:     2009-11-20 18:16:32 -0800 (Fri, 20 Nov 2009)
    Log Message:
    Although Spark RichText does not support link formats, modifying compiled FXG to not generate ActionScript code that will cause compile time exceptions.
    Removing references to Flex Builder 3 in RPC.
    QE notes: N/A
    Doc notes: N/A
    Bugs:
    SDK-24305 - Link format property nodes cause errors on RichText in FXG 2.0
    SDK-24322 - A couple references to Flex Builder 3 in Flex 4 LangRef (and code comments)
    Reviewer: Deepa
    Tests run: checkintests
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-24305
        http://bugs.adobe.com/jira/browse/SDK-24322
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/rpc/src/mx/rpc/xml/XMLDecoder.as
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/fxg/FlexFXG2SWFTranscoder.java

  • I want Firefox to open to my homepage every time after it crashes. I do not want it to return to the tabs and applications that caused the crash. I am willing to lose information. How do I do this?

    Firefox crashes or seizes up when there are too many tabs and applications open, and causes my computer to crash or seize up. I use task manager to close Firefox or I restart my computer. Then, when Firefox restarts again, it automatically re-opens all the tabs and applications that caused the computer to seize or crash in first place. This is a waste of my time. I want Firefox to reopen to my homepage even if it crashes. I am willing to lose information to have Firefox reopen to a low-memory homepage. How do I do this?

    Set the Integer pref browser.sessionstore.max_resumed_crashes to 0 on the about:config page to get the about:sessionrestore page immediately with the first restart after a crash has occurred or the Task Manager was used to close Firefox.
    * http://kb.mozillazine.org/browser.sessionstore.max_resumed_crashes
    That will allow you to deselect the tab(s) that you do not want to reopen, but will allow to reopen other tabs.
    See:
    * http://kb.mozillazine.org/Session_Restore#Restoring_a_session_after_a_crash
    * http://kb.mozillazine.org/Browser.sessionstore.max_resumed_crashes
    See also:
    * https://wiki.mozilla.org/Session_Restore#Preferences
    To open the <i>about:config</i> page, type <b>about:config</b> in the location (address) bar and press the "<i>Enter</i>" key, just like you type the url of a website to open a website.<br />
    If you see a warning then you can confirm that you want to access that page.<br />
    *Use the Filter bar at to top of the about:config page to locate a preference more easily.
    *Preferences that have been modified show as bold (user set).
    *Preferences can be reset to the default via the right-click context menu if they are user set
    *Preferences can be changed via the right-click context menu: Modify (String or Integer) or Toggle (Boolean)

  • How do I fix that at startup, restart Mavericks 10.9.2 always opens the system preference window?

    How do I fix that at startup, restart Mavericks 10.9.2 always opens the system preference window?
    It is not listed in Login items. I tried all the usual fixes plus Diskwarrior rebuild.
                                                                                                                                    W.W.

    I suggest deleting the Canon Network Scanner from Login Items to determine if that is the cause. Not knowing exactly what it does, I suspect it is intended to monitor the printer's supply levels all the time. It's not necessary to do that. You can always determine the printer's ink supply level every time you print something, when its Print dialog appears. You can also check its supply levels by opening System Preferences on your own, and selecting Printers & Scanners.
    Bear in mind Login Items is simply a convenience that loads the programs you specify every time you log in. That feature is less important as it had been in the past since Mavericks will re-open everything that was open when you last logged out, if you select this checkbox:
    If you want to add the Adobe programs to Login Items again, search for them using Spotlight. The Adobe programs themselves should not be causing this behavior.

  • How can we identify the coupon code that triggered the promotion discount in the order?

    Hi,
    As we can create the coupons and assign the promotions to them to give discounts.How can we identity the coupon code that is added the promotion which caused the discount in the order?
    Regards,
    Chede

    I'm giving you an example. Here is how you do it starting with order level promotions. OrderImpl object API below give you orderpirceinfo and second link gives adjustments.
    http://docs.oracle.com/cd/E35319_01/Platform.10-2/apidoc/atg/commerce/order/OrderImpl.html#getPriceInfo()
    From OrderPriceInfo which extends AmountInfo, the following method gives adjustments
    http://docs.oracle.com/cd/E35319_01/Platform.10-2/apidoc/atg/commerce/pricing/AmountInfo.html#getAdjustments()
    Now iterate through adjustments, to get pricingmodel(which is promotion) and coupon applied on order
    PricingAdjustment (ATG Java API)
    PricingAdjustment (ATG Java API)
    Hope this gives you an idea where to start with.
    -karthik

  • SO Wait causes exception occurred within external code called by call library node

    when trying to run some old code that used to work ok, i now get this error message:
    exception occurred within external code called by call library node
    and the vi flagged as calling the exception is SO Wait. the error occurs with different soundcards. does anyone know what is causing this problem?

    Hi Kreuters
    It sounds as if you have a case of memory corruption. Which version of LabVIEW and DAQ (traditonal or DAQmx) are you running and also on which operating system?
    would it be possible for you to post your VI on this thread? in some cases there are ways to fix the problem
    Regards
    YatinM
    NIUK

  • How to check remotely that a PC has been restarted after Labview Runtime 2011 has been installed on it?

    Hello,
    I am deploying a Labview 2011 application on 150 XP-machines in various plants worldwide. Currently all machines still have an old Labview 8.21 runtime (+old DAQmx). I have sent a procedure to my colleagues in the plants so that they install the new runtime (+ new DAQmx). On my side I have built a code to check from my Pc if a certain registry key is present on the 150 PCs which tells me that the new installer ran or not.
    The key that I found is:
    Windows Registry Editor Version 5.00
    [HKEY_CLASSES_ROOT\Installer\Products\1C5E801AE54C4AE43A59FC169F95CA28]
    "ProductName"="NI-DAQmx MAX Configuration Support 9.3.5"
    "PackageCode"="61EEAEC207A28A842B3341ED6809453D"
    "Language"=dword:00000009
    "Version"=dword:0923c001
    "Assignment"=dword:00000001
    "AdvertiseFlags"=dword:00000184
    "InstanceType"=dword:00000000
    "AuthorizedLUAApp"=dword:00000000
    "Clients"=hex(7):3a,00,00,00,00,00
    This works well but it does not tell me that the PC has restarted after the installer has been run. If I do not restart the PC and try to execute my Labview 2011 executable I get a long error message (NIDAQmx not registered,...).
    As it seems difficult to get the properties of a key to know when it was installed I was rather leaning towards checking if a certain DLL (?) has been registered or not. But it is just a vague idea and I do not know how to put that in place.
    I am attaching the current code that I have and that works well but cannot make the difference between Labview 2011 runtime installed and PC restarted or not.
    Thanks for the help
    Christophe
    Solved!
    Go to Solution.
    Attachments:
    Check Remote Registry Key.vi ‏45 KB

    You might look for a file that would be created as part of installation to determine the install date/time (ini or other support file created as part of runtime install)
    Combine that with a query of the station's uptime and you could calculate if the station has been up longer than the time since the install. Not perfect, but should be possible...
    http://en.wikipedia.org/wiki/Uptime#Using_WMI
    wmic /node:"my-server" os get lastbootuptime
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

  • How to set causing Exception correctly?

    I'm trying to nest exceptions. I've written a JUnit tests which does this, but while it works for simple nesting, it doesn't for my more complex Exception.
    The following works:
            Exception e1 = new Exception("bla");
            Exception e2 = new Exception("whatever");
            e1.initCause(e2);
            Assert.assertEquals(e2, e1.getCause());
            Exception e3 = new Exception("yet another exception");
            e2.initCause(e3);
            Assert.assertEquals(e3, e1.getCause().getCause());
            Exception e4 = new Exception("yawn");
            e3.initCause(e4);
            Assert.assertEquals(e4, e1.getCause().getCause().getCause());The following doesn't:
         * The exception to use when a Hibernate transaction can't be ended.
         * The causes of this are created according to the given exceptions.
         * If <code>exception</code> exists:
         * <pre>
         * this
         * |
         * +--> exception
         *      |
         *      +--> hibernateException1
         *           |
         *           +--> hibernateException2 (if it exists)
         * </pre>
         * If <code>exception</code> is <code>null</code>:
         * <pre>
         * this
         * |
         * +--> hibernateException1
         *      |
         *      +--> hibernateException2 (if it exists)
         * </pre>
         * @param errorMessage The error message to show
         * @param exception The exception coming from the business process, which may be <code>null</code>
         * @param hibernateException1 The first Hibernate exception, which <strong>must exist</strong>
         * @param hibernateException2 The second Hibernate exception, which may be <code>null</code>
        public RecoverableSystemException(String errorMessage, Exception exception, HibernateException hibernateException1, HibernateException hibernateException2) {
            super(errorMessage, getCause(exception, hibernateException1, hibernateException2));
         * Gets the causing exception for {@link #RecoverableSystemException(String, Exception, HibernateException, HibernateException)}.
         * @param exception The exception coming from the business process, which may be <code>null</code>
         * @param hibernateException1 The first Hibernate exception, which <strong>must exist</strong>
         * @param hibernateException2 The second Hibernate exception, which may be <code>null</code>
         * @return The causing exception to use for the constructor
        private static Exception getCause(Exception exception, HibernateException hibernateException1, HibernateException hibernateException2) {
            if (hibernateException2 != null && hibernateException1 != null) {
                hibernateException1.initCause(hibernateException2);
            if (exception == null) {
                return hibernateException1;
            else {
                if (hibernateException1 != null) {
                    exception.initCause(hibernateException1);
                return exception;
        }with the test looking like this:
            this.hibernateException1 = new HibernateException("h1");
            this.hibernateException2 = new HibernateException("h2");
            this.businessProcessException = new Exception("e1");
            RecoverableSystemException recoverableSystemException = new RecoverableSystemException("Test", null, this.hibernateException1, this.hibernateException2);
            Assert.assertEquals("Checking Hibernate exception 1", this.hibernateException1, recoverableSystemException.getCause());
            // THIS FAILS
            Assert.assertEquals("Checking Hibernate exception 2", this.hibernateException2, recoverableSystemException.getCause().getCause());Any help would be greatly appreciated!

    initCause is rarely if ever used. It is possible that the way HibernateException is written does not support the use of this call. Have a look at its source to find out if it does.

  • My itunes account wont recognize the access code on my itunes giftcard, how can i fix that?

    my itunes account wont recognize the access code on my itunes giftcard, how can i fix that?

    Without providing details on exactly what you did it is hard to provide an answer.  It's like me saying, "This chocolate cake I made tastes wrong," but not providing the recipe for review.  Maybe it was the garlic in that particular recipe.
    If iTunes is successfully using a previous library which you rename to iTunes Library.itl then that is now the current library.
    Have you restarted your computer and then tried emptying the trash?

  • How can I call contacts from my list without the country code that is registered with that contact?

    I have all my contacts registered with a country code. When I want to make calls from my iphone, I do not want the phone to dial the country code, but only the area code. How can I make that happen?

    Your 3G backup contains your contacts already, you don't need to sync them to Outlook or anything just restore the backup file from the 3G onto the 4S and you should be good to go.
    This kb article should help:
    http://support.apple.com/kb/ht1414

  • HT5622 I updated new software on my phone and now can't use it because its asking for a 4 digit security code that I don't know. How do I find this number?

    I updated new software on my Apple 4S phone and now can't use it because it requires a 4 digit security code that I don't know. The phone store when I originally bought phone bypassed it for me. How do I find it?

    Hey dentallady!
    Here is an article that can help you reset this code:
    iOS: Forgotten passcode or device disabled after entering wrong passcode
    http://support.apple.com/kb/ht1212
    Take care, and thanks for visiting the Apple Support Communities.
    -Braden

Maybe you are looking for

  • Client-side greek character set problem

    hi everyone, i am a .net developer and absolutelly new to oracle, its my first project that i have make oracle and .net co-operate and it's proving to be a nightmare! i ll try and provide as much info as possible to you we have a unix sap server with

  • Need to improve performance for bex queries

    Dear Experts, Here we have bex queries buit on BW infoset, further infoset is buit on 2 dsos and 4 infoobjects. we have built secondary indices to the two dso assuming will improve performance, but still query execution time is very long. Could you s

  • Factory Patterns with Generics

    I am trying to combine the good old factory pattern with generics and could use some advice. I have the following //Base class from which all my things extend public abstract class Thing { //one kind of thing public class ThingOne extends Thing { //a

  • DHCP Server in non-glocal zone

    Is there anyway to run a DHCP server in a non global zone ? Can you give a zone access to a networking device such as qfe3 so dhcpd can catch and respond to requests ? Thanks

  • Carrying imac around upside down....

    Planning on getting the following: http://uk.youtube.com/watch?v=AF_l7mLLXWs how safe is it carrying an 20: imac around in a back-pack upside down? is it more prone to damage (ie not designed for movement like a laptop) by carrying it around. - I pla