Exception handling best practice

whats the best practice for exception handling on ?
- BC
-controller
-view layer (Managed beans)
do we have to handle commit operations on BC so we can rollback like this code
public void save()
// create/update/delete ROW
try
this.getTransaction().commit();
catch(JboException e ){this.getTransaction().rollBack();}
thanks
Edited by: user3674912 on 23/05/2011 05:18 ص

Hi,
IMO, best practices is to handle exceptions as close to their origin. If you can't handle it, you re-throw it as you would in Java so another handler gives it a try
Frank

Similar Messages

  • Exception Handling best practices?

    Hi, Where can I find the tutorial on exception handling best practices on oracle website?
    I am looking for the sun standards for the exception handling.

    By the way, the google keywords to find that tutorial are "java exception tutorial". In general to find a Java tutorial on topic X the google keywords are "java X tutorial". Prefer tutorials from Oracle when scanning the list of links you get back.

  • ESB Exception Handling Best Practices

    I've update the "ESB Transactions, Error Handling and Resubmit" Lesson PDF to include a best practices section. Go to http://otn.oracle.com/goto/esb and click on the link in the Learning more section. Feedback welcome.

    Hi Dave,
    I checked this document yesterday, it contained 18 pages.
    Some great info in the additional 7 pages, just in time as well: at a customer site we are hitting bug 5547165, the rejected messages being empty. I checked the rejection handlers for BPEL and was investigating how these could be used in case of ESB. Seems you have provided the answer.
    Any chance a fix for the bug mentioned here is in the 10.1.3.3 patch set?
    One more thing: by default the rejected messages for ESB are written to file system, in a directory below the 'home' OC4J instance. Could this be turned into a configurable space in a next release?
    Thanks and best regards, Sjoerd

  • MRP Exception Messages - Best practices

    Dear colleagues,
    I am currently dealing with a large SAP installation where system is already live in 50+ countries and the number of manufacturing plants are in hundreds. MRP generates exception messages but the volume is significantly high. Planners have lost faith in these messages thus the client is not getting the full benefit of reacting to MRP exceptions. 
    Have any of you dealt with similar business situations? If yes, what best practices and what system design have you put in place to simplify the process of resolving exception messages.
    Thanks,
    PKV

    Hello Pavan,
    MD06 should be the planner's best friend as it helps him be on top of all the future expected shortfalls, talk to production schedulers or Vendors to bring material on time for production/deliver to customer.
    Best way to handle exception messages in a plant is to divide it by MRP controllers, procurement types external or internal.
    Planners have to analyse MD06 after every MRP run if possible. Atleast once a week go through their MD06.
    However as per my experience most places the material master planning data is not as clean as the planners would like to have. But MD06 offers them an opportunity to update the material master as per their choice. ie planners can change planned delivery time, mrp lot size, mrp type etc..
    You may have to find out why the planners have lost faith in MRP messages. System(MRP) can give you a good result only if  master data is good.
    Hope this helps.
    Thanks,
    Ram

  • Simple HTTP Post Handler - Best Practice?

    I would like to create a fairly simple ASP.Net application that takes an XML record from an HTTP post request, submits it to a process that invokes a command line app that parses the XML file, takes the parsed XML file (as XML), and returns the result. 
    For now the process can be synchronous as the transform has to complete and there are no parallel activities that need to be performed.
    I'm not sure that writing an HTTP Handler is the way to go, but maybe I'm mistaken.  Plus there are no examples of doing that in Visual Studio 2013 using IIS 8.0 or 8.5 and I don't really understand the value of applying a file extension or processing
    an HTTP post to initiate the request, perhaps using a dedicated port.  I already have a class library for handling the process request.
    I'm also a little confused about reading the post request - it seems I can just do it during the page load and that I should be able to extract the first request form field - that of course means using a webform to process the request which seems to be the
    most straight-forward way to do this. So I'm looking for the best practice for fielding this kind of request.  My target server is Windows 2012, but I'm developing with VS 2013 and C# on Windows 7 using IIS Express and configuring IIS is confusing. 
    Overall it is a fairly simple app, but there are so many rich new features in VS 2013 (most of my work has been in VS 2005).  I also want to build a test app and am looking for the best way to do so, although I think I can build a simple client app
    to do that.  The business requirements will be to issue the post request from a MarkLogic xquery request which will take care of any JSON wrappers and balance between multiple Windows servers to handle the load.
    Thanks for any help with this!
    ~Tim

    Hi Tim,
    Thank you for posting in the MSDN forum.
    Actually this forum is to discuss the VS IDE, if this issue is related to web development, you could ask this question in the ASP.NET forum:
    http://forums.asp.net. If then, you could get an answer more quickly and professional. Thanks for your cooperation.
    Best 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.

  • What are default Zend Session handling best practices to prevent Cross Site Request Forgery?

    I have enjoyed the David Powers book Adobe Dreamweaver CS5 with PHP:  Training from the Source - and have put many of the examples into practice.  I have a security related concern that may be tied to the Zend::Auth example in the book.  While this is installed an working on my site:
    <?php
    $failed = FALSE;
    if ($_POST) {
      if (empty($_POST['username']) || empty($_POST['password'])) {
        $failed = TRUE;
      } else {
        require_once('library.php');
        // check the user's credentials
        try {
          $auth = Zend_Auth::getInstance();
          $adapter = new Zend_Auth_Adapter_DbTable($dbRead, 'user', 'login', 'user_pass', 'sha1(?)');
          $adapter->setIdentity($_POST['username']);
          $adapter->setCredential($_POST['password']);
          $result = $auth->authenticate($adapter);
          if ($result->isValid()) {
            $storage = $auth->getStorage();
            $storage->write($adapter->getResultRowObject(array(
              'ID', 'login',  'user_first', 'user_last', 'user_role')));
            header('Location: /member/index.php');
            exit;
          } else {
            $failed = TRUE;
        } catch (Exception $e) {
          echo $e->getMessage();
    if (isset($_GET['logout'])) {
      require_once('library.php');
      try {
        $auth = Zend_Auth::getInstance();
        $auth->clearIdentity();
      } catch (Exception $e) {
        echo $e->getMessage();
    Apparently, there is  very limited protection against Cross Site Request Forgery, where the resulting SessionID could be easily hijacked?  I am using the Zend Community edition (I have 1.11.11).     I have an observation from a client that this authentication is not up to snuff. 
    To boil it down: 
    1.  Is there a Zend configuration file that might have some settings to upgrade the Session and or authentication security basics? I'm wondering specifically about the settings in /library/Zend/session.php? Ie secure the session against a changing user IP, and invoking some other session handling stuff (time-out etc). 
    2.  If I understand it correctly, "salting" won't help with this, unless it's added/checked via a hidden POST at login time? 
    Ideally, the man himself, David Powers would jump in here - but I'll take any help I can get!
    Thanks!

    Might ask them over here.
    http://forums.asp.net/1146.aspx/1?MVC
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • ICM Scripting Error Handling Best Practice

    Can someone tell me what is the best way to handle errors in ICM scripting. For example false node on Send to VRU or Run Ext Script node, I normally handle this with calltypes for errors and then continue the callflow. But recently I noticed that some of my clients are using peripheral variable to store an error message instead of calltype. I am just wonderinmg which is the best option?

    I don't think you need a call type, I usually set PV10 = "Error: XYZ".  Creating a call type just seems a little redundant, however it would make it easier on the reporting side as you don't have to create any custom queries to search for a specific error type.
    david

  • Good exception handling policy for Java web application

    I'm looking for a good exception handling policy for Java web application. First I found this Java exception handling best practices - How To Do In Java which says that you should never catch the Trowable class nor use e.printStackTrace();
    Then I found this Oracle page The Message-Driven Bean Class - The Java EE 6 Tutorial, which does just that. So now I'm confused. Is there a good page online for an exception handling policy for Java EE Web applications? I have a hard time finding one. I've read that you should not catch the Exception class. I've been catching it previously to make sure that some unknown exception doesn't slip through early in the loop and stops all other customers from executing later on in the loop. We have a loop which runs once a minute implemented using the Quartz framework. Is it OK if you just change the implementation to catch the RuntimeException class instead of the Exception class? We're using Java 7 and the Jetty Servlet Container.

    I'm looking for a good exception handling policy for Java web application.
    If you have not done so I suggest you start by reviewing the several trails in The Java Tutorials.
    Those trails cover both HOW to use exceptions and WHEN to use them.
    This trail discusses  the 'controversy' you mention regarding 'Unchecked Exceptions'
    http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html
    Unchecked Exceptions — The Controversy
    Because the Java programming language does not require methods to catch or to specify unchecked exceptions (RuntimeException, Error, and their subclasses), programmers may be tempted to write code that throws only unchecked exceptions or to make all their exception subclasses inherit from RuntimeException. Both of these shortcuts allow programmers to write code without bothering with compiler errors and without bothering to specify or to catch any exceptions. Although this may seem convenient to the programmer, it sidesteps the intent of the catch or specify requirement and can cause problems for others using your classes.
    Why did the designers decide to force a method to specify all uncaught checked exceptions that can be thrown within its scope? Any Exception that can be thrown by a method is part of the method's public programming interface. Those who call a method must know about the exceptions that a method can throw so that they can decide what to do about them. These exceptions are as much a part of that method's programming interface as its parameters and return value.
    The next question might be: "If it's so good to document a method's API, including the exceptions it can throw, why not specify runtime exceptions too?" Runtime exceptions represent problems that are the result of a programming problem, and as such, the API client code cannot reasonably be expected to recover from them or to handle them in any way. Such problems include arithmetic exceptions, such as dividing by zero; pointer exceptions, such as trying to access an object through a null reference; and indexing exceptions, such as attempting to access an array element through an index that is too large or too small.
    Generally don't catch an exception unless you plan to HANDLE the exception. Logging, by itself is NOT handliing.
    First I found this Java exception handling best practices - How To Do In Java which says that you should never catch the Trowable class nor use e.printStackTrace(); 
    That article, like many, has some good advice and some poor or even bad advice. You get what you pay for!
    I've read that you should not catch the Exception class.
    Ok - but all that does is indicate that a problem of some sort happened somewhere. Not very useful info. Java goes to a lot of trouble to provide specific exceptions for specific problems.
    I've been catching it previously to make sure that some unknown exception doesn't slip through early in the loop and stops all other customers from executing later on in the loop.
    If the exception is 'unknown' then maybe it NEEDS to 'stop all other customers from executing later on in the loop'.
    That is EXACTLY why you don't want to do that. You need to identify which exceptions should NOT stop processing and which ones should.
    Some 'unknown' exceptions can NOT be recovered and indicate a serious problem, perhaps with the JVM itself. You can NOT just blindly keep executing and ignore them without risking data corruption and/or the integrity of the entire system Java is running on.
    Is it OK if you just change the implementation to catch the RuntimeException class instead of the Exception class? We're using Java 7 and the Jetty Servlet Container.
    No - not if you want a well-behaved system.
    Don't catch exceptions unless you HANDLE/resolve them. There are times when it makes sense to log the exception (which does NOT handle it) and then raise it again so that it gets handled properly later. Yes - I know that is contrary to the advice given in that article but, IMHO, that article is wrong about that point.
    If you have ever had to maintain/fix/support someone else's Java code you should already understand how difficult it can be to find WHERE a problem occurs and WHAT the exact problem is when exceptions are not handled properly.

  • Best Practice for Implementing Exception Handling in BPEL

    Hi All,
    what is the best practice and the approach to follow Exception Handling in BPEL.
    1) Do we need to implement Exception Handling in BPEL as we do in Java, means
         method 3 throws error to method 2 (if any) and
         method 2 throws error to method 1 (if any) and
         finally method 1 throws error to the main Class.
    If we replicate the above scenario to BPEL
    In BPEL main Scope have Custom Fault, Catch ALL
         Each Invoke is surrounded by a Scope Activity with Remote Fault, Binding Fault & Custom Fault
    and follow the paradigm of Java, assuming we have Inner Scopes
         [ OR ]
    2) In BPEL main Scope have all exceptions defined like
         Remote Fault,
         Binding Fault,
         anyOther System Fault (selectionFailure / forcedTermination),
         Custom Fault (if required) and
         CatchALL
         and also
         each Invoke is surrounded by a Scopes Acitivity with Custom Fault (business fault) exception Handling
    I feel 1st one may not be a good practice, may be i am wrong...
    Any Suggestions from experts.
    Thanks in Advance
    anvv sharma

    Hi-
    In you can create different scope and use catch branch to catch binding, remote, custom faults, business faults etc. If an error happens in a scope it will not move to the next scope( eg: you have 3 scope, error occured in 2nd scope then it will not propogate to the 3rd scope. One thing to be noticed here is your transaction in the 1st scope doesnt gets commited when an error happens in 2d scope).
    You can have a catch all to catch error which are not being caught at catch level. So if any error happens which is not defined in catch block then then it will be caught in catch all branch.
    Edited by: 333333 on Apr 12, 2011 9:39 AM

  • Best Practice Exception Handling.

    Hi,
    Please consider two scenarios:
    Scenario 1:
    DECLARE
      l_emp   scott.emp.ename%TYPE;
      l_dname scott.dept.dname%TYPE;
    BEGIN
      BEGIN
        SELECT ename INTO l_emp FROM emp WHERE empno = 7934;
      EXCEPTION
        WHEN no_data_found THEN
          dbms_output.put_line('No big deal');
          NULL;
        WHEN too_many_rows THEN
          dbms_output.put_line('It is a big deal');
          RAISE;
        WHEN OTHERS THEN
          RAISE;
      END;
      BEGIN
        SELECT dname INTO l_dname FROM dept WHERE deptno = 1;
      EXCEPTION
        WHEN no_data_found THEN
          dbms_output.put_line('It is a big deal');
          RAISE;
        WHEN too_many_rows THEN
          dbms_output.put_line('It is a big deal');
          RAISE;
        WHEN OTHERS THEN
          RAISE;
      END;
    EXCEPTION
      WHEN OTHERS THEN
        RAISE;
    END;
    Scenario 2:
    DECLARE
      l_point_of_error NUMBER;
      l_emp            scott.emp.ename%TYPE;
      l_dname          scott.dept.dname%TYPE;
    BEGIN
      l_point_of_error := 1;
      now write some implicit cursors-
      SELECT ename INTO l_emp FROM emp WHERE empno = 7934;
      l_point_of_error := 2;
      SELECT dname INTO l_dname FROM dept WHERE deptno = 1;
    EXCEPTION
      WHEN no_data_found THEN
        CASE l_point_of_error
          WHEN 1 THEN
            dbms_output.put_line('No big deal');
            NULL;
          WHEN 2 THEN
            dbms_output.put_line('It is a big deal');
            RAISE;
          ELSE
            dbms_output.put_line('I have an idea which block this errored out on...but I want or HAVE TO raise the error');
            RAISE;
        END CASE;
        NULL;
      WHEN too_many_rows THEN
        CASE l_point_of_error
          WHEN 1 THEN
            dbms_output.put_line('It is a big deal');
            RAISE;
          WHEN 2 THEN
            dbms_output.put_line('It is a big deal');
            RAISE;
          ELSE
            dbms_output.put_line('I have an idea which block this errored out on...but I want or HAVE TO raise the error');
            RAISE;
        END CASE;
        NULL;
      WHEN OTHERS THEN
        RAISE;
    END;
    /What do you think is the right approach?
    The one thing I can think of using Scenario 2, it will be a nightmare to handle the 'case' statements in the final exception catcher when the number of blocks to handle are more.
    Also, Scenario 2 also uses ONE more variable to be assigned (more processing time maybe??).
    I am also told that Scenario 2 is used extensively used by Oracle Applications PL/SQL Api's.
    But, if you can suggest which do you think is the best practice is? I would really appreciate it.
    Thank you,
    Rahul

    My bad 3360:
    I didn't mention the error logging think in OP and I use it in my code all the time and forgot to put it in OP.
    Anyway, I use Tom Kyte's who_am_i and who_called_me in my error logging to figure out the line number of the error.
    * One failure was caused by the error log table running out of space because no one ever looked at it and didn't realize it had hundreds of thousands of exceptions in it. Yes, you are absolutely right. Yes somebody(the developer(s) ) have to take care of the error logging table (try to see what errors out and why).
    P.S: I am gonna stick with Scenario 1 (with the error logging of course :) ) according to Todd Barry's comments and I have no idea why Oracle Applications uses Scenario 2. Can anybody tell me why (maybe it's just bad coding on Oracle Apps part?).
    Thank you,
    Rahul.

  • What are the best practices for exception handling in n-tier applications?

    What are the best practices for exception handling in n-tier applications?
    The application is a fat client based on MVVM pattern with .NET framework.

    What are the best practices for exception handling in n-tier applications?
    The application is a fat client based on MVVM pattern with
    .NET framework.
    That would be to catch all exceptions at a single point in the n-tier solution, log it and create user friendly messages displayed to the user. 

  • Best practices for dealing with Exceptions on storage members

    We recently encountered an issue where one of our DistributedCaches was terminating itself and restarting due to an RuntimeException being thrown from our code (see below). As usual, the issue was in our own code and we have updated it to not throw a RuntimeException under any circumstances.
    I would like to know if there are any best practices for Exception handling, other than catching Exceptions and logging them. Should we always trap Exceptions and ensure that they do not bubble back up to code that is running from the Coherence jar? Is there a way to configure Coherence so that our DistributedCaches do not terminate even when custom Filters and such throw RuntimeExceptions?
    thanks, Aidan
    Exception below:
    2010-02-09 12:40:39.222/88477.977 Oracle Coherence GE 3.4.2/411 <Error> (thread=DistributedCache:StyleCache, member=48): An exception (java.lang.RuntimeException) occurred reading Message AggregateFilterRequest Type=31 for Service=DistributedCache{Name=StyleCache, State=(SERVICE_STARTED), LocalStorage=enabled, PartitionCount=1021, BackupCount=1, AssignedPartitions=201, BackupPartitions=204}
    2010-02-09 12:40:39.222/88477.977 Oracle Coherence GE 3.4.2/411 <Error> (thread=DistributedCache:StyleCache, member=48): Terminating DistributedCache due to unhandled exception: java.lang.RuntimeException

    Bob - Here is the full stacktrace:
    2010-02-09 13:04:22.653/90182.274 Oracle Coherence GE 3.4.2/411 <Error> (thread=DistributedCache:StyleCache, member=47): An exception (java.lang.RuntimeException) occurred reading Message AggregateFilterRequest Type=31 for Service=DistributedCache{Name=StyleCache, State=(SERVICE_STARTED), LocalStorage=enabled, PartitionCount=1021, BackupCount=1, AssignedPartitions=205, BackupPartitions=204}
    2010-02-09 13:04:22.653/90182.274 Oracle Coherence GE 3.4.2/411 <Error> (thread=DistributedCache:StyleCache, member=47): Terminating DistributedCache due to unhandled exception: java.lang.RuntimeException
    2010-02-09 13:04:22.653/90182.274 Oracle Coherence GE 3.4.2/411 <Error> (thread=DistributedCache:StyleCache, member=47):
    java.lang.RuntimeException: java.lang.ClassNotFoundException: com.edmunds.vehicle.Style$PublicationState
         at com.edmunds.common.coherence.EdmundsEqualsFilter.readExternal(EdmundsEqualsFilter.java:84)
         at com.tangosol.io.pof.PortableObjectSerializer.initialize(PortableObjectSerializer.java:153)
         at com.tangosol.io.pof.PortableObjectSerializer.deserialize(PortableObjectSerializer.java:128)
         at com.tangosol.io.pof.PofBufferReader.readAsObject(PofBufferReader.java:3284)
         at com.tangosol.io.pof.PofBufferReader.readAsObjectArray(PofBufferReader.java:3328)
         at com.tangosol.io.pof.PofBufferReader.readObjectArray(PofBufferReader.java:2168)
         at com.tangosol.util.filter.ArrayFilter.readExternal(ArrayFilter.java:243)
         at com.tangosol.io.pof.PortableObjectSerializer.initialize(PortableObjectSerializer.java:153)
         at com.tangosol.io.pof.PortableObjectSerializer.deserialize(PortableObjectSerializer.java:128)
         at com.tangosol.io.pof.PofBufferReader.readAsObject(PofBufferReader.java:3284)
         at com.tangosol.io.pof.PofBufferReader.readAsObjectArray(PofBufferReader.java:3328)
         at com.tangosol.io.pof.PofBufferReader.readObjectArray(PofBufferReader.java:2168)
         at com.tangosol.util.filter.ArrayFilter.readExternal(ArrayFilter.java:243)
         at com.tangosol.io.pof.PortableObjectSerializer.initialize(PortableObjectSerializer.java:153)
         at com.tangosol.io.pof.PortableObjectSerializer.deserialize(PortableObjectSerializer.java:128)
         at com.tangosol.io.pof.PofBufferReader.readAsObject(PofBufferReader.java:3284)
         at com.tangosol.io.pof.PofBufferReader.readObject(PofBufferReader.java:2599)
         at com.tangosol.io.pof.ConfigurablePofContext.deserialize(ConfigurablePofContext.java:348)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.Service.readObject(Service.CDB:4)
         at com.tangosol.coherence.component.net.Message.readObject(Message.CDB:1)
         at com.tangosol.coherence.component.net.message.requestMessage.distributedCacheRequest.partialRequest.FilterRequest.read(FilterRequest.CDB:8)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$AggregateFilterRequest.read(DistributedCache.CDB:4)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onNotify(Grid.CDB:117)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache.onNotify(DistributedCache.CDB:3)
         at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:37)
         at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.ClassNotFoundException: com.edmunds.vehicle.Style$PublicationState
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:169)
         at com.edmunds.common.coherence.EdmundsEqualsFilter.readExternal(EdmundsEqualsFilter.java:82)
         ... 25 more
    2010-02-09 13:04:23.122/90182.743 Oracle Coherence GE 3.4.2/411 <Info> (thread=Main Thread, member=47): Restarting Service: StyleCacheOur code was doing something simple like
    catch(Exception e){
        throw new RuntimeException(e);
    }Would using the ensureRuntimeException call do anything for us here?
    Edited by: aidanol on Feb 12, 2010 11:41 AM

  • What is the best practice to handle JPA methods in JSF app?

    I am building a JSF-JPA web app(No EJB).
    I have several methods that has JPA QL inside.
    Because I have to put those methods inside JSF beans to inject EntityManagerFactory (am I right about this?).
    And I do want to separate those methods from regular JSF beans which are used by page authors.
    And I may need to use them in different JSF managed beans.
    My question here is that what is the best practice to handle that?
    I. write a or a few separate JSF Beans and inject them into regular Beans?
    II. write a or a few separate JSF Beans and access them into regular Beans using FacesContext?
    III. others?
    Waiting to hear from you opinions.

    You can create named queries on your Entities themselves then just call entityMgr.createNamedQuery("nameOfQuery");
    Normally, we put these named queries in the class of the entity which will be returned. This allows for all information pertaining to a given entity and all ways of accessing that entity (except em.find() and stuff, of course) to be in one place. As long as the entity is defined in your persistence.xml file, any named queries which reside on that entity will be available through the EntityManager.
    As for the EntityManagerFactory, we normally create an application scope bean which holds the factory itself (because this is a heavy-weight object) and then just get all EntityManager instances from that by injecting this bean into whatever needs it. For example, I might have:
    //emfBB is the injected app scope bean which holds the entity manager factory.
    private EmfBB emfBB;
    private void lookupSomeData()
    EntityManager em = this.getEmfBB().getEmf()
    I hope this answered your question?
    ~Zack
    Edited by: zmarr on Nov 6, 2008 1:29 PM

  • Best practices for checked exceptions in Runnable.run

    Runnable.run cannot be modified to pass a checked exception to its parent, so it must deal with any checked exceptions that occur. Simply logging the error is inadequate, and I am wondering if there are any "best practices" on how to deal with this situation.
    Let me give a real-world example of what I'm talking about.
    When writing I/O code for a single-threaded app, I'll break the logic into methods, and declare these methods as throwing an IOException. Basically, I'll ignore all exceptions and simply pass them up the stack, knowing that Java's checked exception facility will force the caller to deal with error conditions.
    Some time later, I might try to improve performance by making the I/O code multithreaded. But now things get tricky because I can no longer ignore exceptions. When I refactor the code into a Runnable, it cannot simply toss IOExceptions to some future unnamed caller. It must now catch and handle the IOException. Of course, dealing with the problem by simply catching and logging the exception is bad, because the code that spawned the I/O thread won't know that anything went wrong. Instead, the I/O thread must somehow notify its parent that the exception occurred. But just how to do this is not straightforward.
    Any thoughts? Thanks.

    My suggestion: don't use Threads and Runnables like this.
    Instead implement Callable which can throw any Exception.
    Then use an ExecutorService to run that Callable.
    This will return a Future object which can throw an ExecutionException on get(), which you can then handle.
    This has the additional advantage that you can easily switch from a single-threaded serialized execution to a multi-threaded one by switching ExecutorService implementations (or even by tweaking the parameters of the ExecutorService implementation).

  • Best practice on handling a datacontrol based on a changing webservice

    Is there any best practice on how to handle changes to a datacontrol, when a webservice changes ?, it seems the information on
    portnumbers, servernames etc. is placed in a number of files, an optimal solution seems to be that Jdeveloper would have functionality
    to regenerate all relevant files based on changes to the WSDL, but this does not seem to be supported in Jdeveloper 11g
    Regards
    Ole Spielberg

    Hi,
    I think in this case you would better use a WS proxy, wrap this in a POJO and create a data control from this. This allows you to set the port and host programmatically. I agree that there should be a better option to do the same in the WS data control
    Frank

Maybe you are looking for