Correct way to handle an exception in a constructor?

Hi I was wondering if anyone could tell me if I implemented my code correctly. It compiles and runs fine, I'm just wondering if there is a more efficient or better way to do this.
     static Cabin cabinTest;
public static void main(String[] args)
          testEquals();
          testCompareTo();
          try
               cabinTest = new Cabin(5, 2, true);
          catch(Exception e)
               System.out.println("Invalid Input");
public Cabin (int cabinNumber, int rooms, boolean kitchen) throws Exception
          super("C" + cabinNumber, rooms==1 ? ONE_ROOM_RATE : TWO_ROOM_RATE,
                 rooms==1? ONE_ROOM_GUESTS : TWO_ROOM_GUESTS);
               this.rooms = rooms;
               this.kitchen = kitchen;
          

Thanks for your response.
I think I have done all I can do as far as what you pointed out. This is a class assignment so I am working with code and instructions I have been given.
The teacher said the constructor throws Exception. Here is the UML she provided for the constructor of the class she had us write.
+Cabin(in cabinNumber: int, in rooms: int,
         in kitchen: boolean) throws ExceptionAnd, this is simple test code :)
Thanks again

Similar Messages

  • Is there a way to handle system exception ERROR_MESSAGE?

    Hi,
    I have a program executed in background, which produces a bunch of consecutive documents for a set of Bulk Shipments -> TD Loading and TD Delivery Confirmation. To create those documents I use function modules 'OIGI_LOADING_CREATE' and 'OIGI_DEL_CONF_CREATE'  - both from Industry-Solution Oil-and_Gas (IS-Oil).
    In some cases these FM-s produces error messages (E-type) which cancel execution of the program and broke my flow-logic.
    Below are few messages recorded in a job log for my task:
    18.08.2005 15:56:41 Job started                                                                         
    18.08.2005 15:56:41 Step 001 started (program /PTRL/TAS_POSTPONDED_SYNC, variant , user name IMUTAFCHIEV)
    18.08.2005 15:56:58 Shipment 180753 saved                                                               
    18.08.2005 15:57:06 The plant data of the material 177 is locked by the user BMINKOV                    
    18.08.2005 15:57:06 The plant data of the material 177 is locked by the user BMINKOV                    
    18.08.2005 15:57:06 The plant data of the material 177 is locked by the user BMINKOV                    
    18.08.2005 15:57:06 Job cancelled after system exception ERROR_MESSAGE                                  
    Both function modules are not designed to handle any exceptions, and in owr environment (4.6c) there is no documented system exception 'ERROR_MESSAGE' which to be handled in CATCH-ENDCATCH block.
    Is there a way to handle this exception and to track the list of error messages produced by some FM into an internal table, log, whatever, as it is done in the log of the background job. I need to find a way write these messages in my log-tables and to proceed further with my flow-logic.
    FYI: my program executes an RFC call to a remote system and retrieve a list of documents which need to be synchronized with R/3. I loose information, if the R/3 broke my flow-logic.
    Any help would be highly appresiated.
    Many thanks in advance.
    Ivaylo Mutafchiev

    Sven,
    I made few programs where we used business scenario:
    IS-Oil Shipment => IS-Oil Loading Confirmation => IS-Oil Delivery Confirmation.
    All of them are based on Function Module call:
    1. OIGI_LOADING_CREATE and
    2. OIGI_DEL_CONF_CREATE.
    To load shipment I call 1st FM in a way:
      CALL FUNCTION 'OIGI_LOADING_CREATE' DESTINATION 'NONE'
           EXPORTING
                I_SUBRC     = 9  "save and commit
                I_SHNUMBER  = shNumber
                I_VEHICLE   = vehicle
                I_LDPLT     = plant
                I_LDDATE    = loadDate
                I_LDTIME    = loadTime
                I_LDCDAT    = loadDate
                I_VEH_NR    = veh_nr
           TABLES
                T_OIGISVMQ  = quantity_items
                T_OIGISVMQ2 = hpm_append
                T_OIGISIQ   = doc_quan_items
           EXCEPTIONS
                COMMUNICATION_FAILURE = 1 MESSAGE p_error
                SYSTEM_FAILURE = 2 MESSAGE p_error.
    To confirm shipment (status 4) I call the same FM with:
      CALL FUNCTION 'OIGI_LOADING_CREATE' DESTINATION 'NONE'
           EXPORTING
                I_SUBRC    = 39  "confirm & commit 2nd step
                I_SHNUMBER = shNumber
                I_VEHICLE  = vehicle
                I_LDPLT    = werks
           EXCEPTIONS
                COMMUNICATION_FAILURE = 1 MESSAGE sh_error
                SYSTEM_FAILURE = 2 MESSAGE sh_error.
    And finaly to finish process (status = 6) I call 2nd FM in a way:
      CALL FUNCTION 'OIGI_DEL_CONF_CREATE' DESTINATION 'NONE'
           EXPORTING
                I_SUBRC         = 19  "save, confirm and commit
                I_SHNUMBER      = shNumber
                I_RAPID_CONFIRM = 'X'
                I_DDCDAT        = loadDate
                I_DLDATE        = loadDate
                I_DLTIME        = loadTime
           EXCEPTIONS
                COMMUNICATION_FAILURE = 1 MESSAGE p_error
                SYSTEM_FAILURE = 2 MESSAGE p_error.
    FYI: It tooks me some time to 'investigate' and find correct use of these function modules. And I worked VERY CLOSE with our SD consultant.
    For details (what the export parameters and tables consist of) and sample code, please contact me at:
    ivaylo dot mutafchiev at vbs dot bg
    I would be glad to share my knowlege.
    Regards,
    Ivaylo

  • What's the correct way to handle changes in RDBMS/DBadapter?

    In my project all changes to the database are not done via Jdeveloper but via TOAD. This means DBadapters must be made aware of changes in the database.
    I tried to re-run the DBad.apter wizard twice (2 different services) - to make it aware of changes in the DB. Both times it failed. I think was after the import database tab. The next tab was just blank.
    So what's the correct way of reconile changes in the db backwards into Jdev?
    BTW, in the DBadapter wiz its not possible the remove a already imported table. How do I come across the situation where I want the DBadapter to point to af different table? - and possibly remove old references to another one - which might have been removed in the DB.
    As It is now - I have to re-work all my DBadapters, which is not very much fun...
    Rgds, Henrik

    Trust me, I hv done that umpteen nbr of times.
    I hate BA's coming to me with changes, for which I hv to modify the DB adapter.
    One big loop-hole with BPEL is if we try to modify the adapters/toplink, it doesnt tend to work properly.
    The manthra for such modifications is ... "recreate", which is definetely not a good practise.
    You may not like but gottu live with it, my friend.
    Pointing to a different table, I achieve it by doing a "Shift+Delete" to all the references of the old table in the BPEL project ... :|
    There isnt a specific provision in the wzd (I am not sure of the latest version, though).

  • Correct way to handle the updated object

    Hi,
    I have a thread, test2.java, that periodically update a object that pass from test.java. In test.java, the "data" object need to be most updated coz this object is used in other thread also. I can ensure that only test2.java do the write, others threads are read only.
    My question is: I can write some dirty code to do what I want. But for a programmer, I want to know the formal, oo way to handle this situation.
    Thanks.
    Tommy
    public class test{
    data d;
    test2 t2;
    public test(){
    d = new data(1, getClass().toString());
    t2 = new test2(d);
    t2.start();
    public void runServices(){
    while(true){
    //If i don't do anything, the following code only print out
    //the instance that i init. here.. Not the updated one
    System.out.println(d.toString());
    try{
    Thread.sleep(5000);
    }catch(InterruptedException ex){}
    public static void main(String[] args){
    test t = new test();
    t.runServices();
    * This class will periodically update the "data" object that
    * passed from test.java
    public class test2 extends Thread{
    int count = 1;
    data d;
    public test2(data a){
    this.d = a;
    public void run(){
    while(true){
    d = new data(count++, getClass().toString());
    System.out.println(d.toString());
    try{
    sleep(5000);
    }catch(InterruptedException ex){}
    public class data{
    int count;
    String s = "";
    public data(int a, String b){
    count = a;
    s = b;
    public String toString(){
    return s + " count:" + count;

    Sorry nearly missed that :(
    You should try to modify the instance of data you have been given in the constructor for test2 instead of creating a new object:
    * This class will periodically update the "data" object that
    * passed from test.java
    public class test2 extends Thread {
      int count = 1;
      data d;
      public test2(data a) {
        this.d = a;
      public void run() {
        while(true) {
          d.refreshWith(count++, getClass().toString());
          System.out.println(d.toString());
         try {
           sleep(5000);
         } catch(InterruptedException ex){}
    }

  • Wich is correct way to handle Workflow of documents ?

    We are starting a project to handle Workflow of documents.
    We have an Enterprise with some Users that edit and publish documents;
    and related subcompanies that have Users that read only the documents.
    We have to handle the revisions of documents, the process phases and the validation
    of a revisor for each phase and also control the document access.
    Our backend database is Oracle 8 for Wordgroup (in the Enterprise) and IIS for the client access (from subcompanies).
    We want to use this architecture : client (HTML) and server (servlet, JSP).
    These documents are written with Word97 and are stored in Oracle 8.
    We plan in the future on updating Oracle 8 FWG > Oracle8 Enterprise > Oracle8i and the migration from IIS (NT Web Server) to (UNIX Solaris).
    My questions are:
    1) How control the open and save of documents with Oracle connection ?
    2) Is better to store the documents inside Oracle or just insert the URL in tables ?
    3) If I want to use ConText cartridge for searching mechanism where I have to store
    this documents ?
    4) For the servlets I need an Application Server ? Wich release ?
    Could you help me to get the correct solution. I would appreciate any suggestions.
    Thanks
    Lorenzo Baldovini.
    [email protected]

    Hi,
    You really need to take a look at the XMLDB Developers guide.
    For updating XML with SQL/XML see UPDATEXML and for XQuery see [Using XQuery with Oracle XMLDB|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14259/xdb_xquery.htm#sthref1673]
    HTH,
    Chris

  • Clients connect to wifi with certificate that expires every month - correct way to handle expired certificates?

    Hi all
    I'm sorry if this is the wrong forum to ask this question. Also my knowledge in this area is somewhat limited, which I why I need your help :-)
    We use wireless networks primarily in my company for all our clients and use a certificate to authenticate to the network. This certificate expires after 1 month and we automatically renew them 1 week before expiry. Relatively often we have users that
    are not connected to the network for a few weeks or more and then the certificate expires before being renewed. Then we have to connect them to the wired network to get the certificate updated, so they can connect to the wireless network again.
    What is the correct approach to solve this issue? We feel extending the life of the certificate would be a too big security compromise. Is there some way you could automatically allow an expired certificate briefly with the sole purpose of renewing the certificate?
    Or how would you normally resolve this issue?
    Thanks for any help/knowledge you can provide :-)

    > Setting the validity period that high, means that the certificate could be cracked before expiry.
    then you should be scary of CAs which validity is 10 or more years. And they use the same cryptography as end-entity certificates (key length and signature algorithms). It is a paranoya. Just make sure if client certificates use at least 2048 bit long
    keys and use SHA1 (or better) signature algorithm. In this case there is a little chance that certificate will be successfully cracked in 2 years.
    If there is an evidence (or indications) of client private key compromise -- immediately revoke the certificate and publish new CRL ASAP. You cannot protect clients from key compromise by using short-living certificates, because key compromise is ususally
    achieved by gaining a control over the private key (malware on client computer). Therefore, there is nothing wrong in issuing client certificates with 1 or 2 year validity.
    My weblog: en-us.sysadmins.lv
    PowerShell PKI Module: pspki.codeplex.com
    PowerShell Cmdlet Help Editor pscmdlethelpeditor.codeplex.com
    Check out new: SSL Certificate Verifier
    Check out new:
    PowerShell FCIV tool.

  • What's the correct way to handle some simple database actions with EF 6.1.3?

    I realize the title is very generic, so I'll go into more detail. I have experience working with Entity Framework, but most of my experience is with older versions of EF. Specifically EF 4.x. I'm writing a very simple app; it will return records from 2 look
    up tables, and insert a record into a data table. With EF 4.x what I would do is create a data model, a .EDMX file and then place the relevant tables onto the design surface. Then I'd have a data context object to work with in my C# code.
    However I get the feeling that it's different with newer versions of EF. I'm not even sure that there's a design surface any more. I've seen things like DbSet objects and other things. And I've done a little bit of development using newer versions of
    EF, specifically code first, or what might be more appropriate in this case code first with existing data. Because most certainly that is what I've got here. I don't want to replace or wipe out the existing data! And yet I tend to think more in terms
    of data contexts; I want to use what's appropriate for the newer versions of EF.
    I'm sure that ultimately it would be good for me to get into a class (which unfortunately won't happen) or do some training on my own. I'll do that as I can, but in the interim I'd like to know how I can do what I want to do with two lookup tables and
    one data table that I've got to insert one record at a time into. Could someone please give me a quick run down as to how to do this?
    Rod

    Never mind. I found a good example of what I'm looking for on Channel 9,
    Code First to Existing Database (EF 6.1 Onwards). This is what I've done before, but not too often. Anyway, I hope this will help others.
    Rod

  • Correct way to handle updates of XMLtype columns in standard tables.

    Hello to whoever may read this,
    I am currently studying the XML functionality of oracle DB for a uni project.
    We have been asked to compare/contrast solutions to publishing product and price data for data stored in standard relational tables, and data stored in XML type tables. For extra marks, i am looking at a table containing an XMLType column for multiple items of data relating to the primarykey.
    I have managed to get my head around publishing the data - pretty straight forward, but we have also been asked to show how we can update data, which isn't a problem within the standard tables/columns, but when it comes to the XMLType columns/tables, i dont have a clue.
    At the moment i am working on trying to update an XMLtype column. The table itself is a "product" table, and contains product information, as well as an XMLType column containing multiple changes to the prices. In the relational tables, this "product" table has a one-to-many link to another table called price_history which contains details about past prices (which is populated by a trigger on update/insert of a new price). But in this table all the product changes are stored in XML format in the XML type column "prices".
    Table columns: id number(4), name varchar2(25), prices xmltype;
    example data: 1781, CDW 20/48/E, <product_prices><price_change>
    <change_id>1</change_id>
    <date_changed>2009-10-13</date_changed>
    <details>price increased</details>
    <new_value>234</new_value>
    </price_change>
    <price_change>
    <change_id>2</change_id>
    <date_changed>2009-10-13</date_changed>
    <details>price increased</details>
    <new_value>235</new_value>
    </price_change></product_prices>
    We need to give examples of an update. I have been looking around the net, and these forums for a solution now for about 4 hours. My own thoughts are that to update this with a new price change i need to, SELECT the current data INTO a variable, then concatenate that variable with the new price change info e.g.
    <price_change>
    <change_id>3</change_id>
    <date_changed>2009-10-13</date_changed>
    <details>price decreased</details>
    <new_value>230</new_value>
    </price_change>
    then insert that whole chunk of data again to overwrite the old data.
    Now im fairly certain there is some function somewhere which will allow me to do this update/insert operation without going through this process... After i am done with this update of XMLType column data, i need to tackle updating data in an XMLType Table with XQuery(? apparently), so if you have any pointers for that please let me know.
    Could one of you experts point me in the right direction for this? Any advice at this stage is a great help and will stop me losing my mind.
    p.s. im sorry about the lengthy description of the problem/solution required. How to describle something i dont understand? I ask myself.

    Hi,
    You really need to take a look at the XMLDB Developers guide.
    For updating XML with SQL/XML see UPDATEXML and for XQuery see [Using XQuery with Oracle XMLDB|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14259/xdb_xquery.htm#sthref1673]
    HTH,
    Chris

  • How to handle the Exception when RegisterEventProcessorAsync

    In our Cloud Service project, we have 2 instances for work role (deploy to Azure), the work role is consume events from the EventHub using EventProcessorHost).
    When we want to register EventProcessor to consume data (see below):
    await eventProcessorHost.RegisterEventProcessorAsync<eventProcessor>();
    Sometimes we will got the Exception:
    Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (412) There is
    currently a lease on the blob and no lease ID was specified in the request.. ---> System.Net.WebException: The remote server returned an error: (412)
    There is currently a lease on the blob and no lease ID was specified in the request..
      at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpResponseParsers.ProcessExpectedStatusCodeNoException[T](HttpStatusCode expectedStatusCode, HttpStatusCode actualStatusCode, T retVal, StorageCommandBase`1 cmd, Exception ex)
       at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpResponseParsers.ProcessExpectedStatusCodeNoException[T](HttpStatusCode expectedStatusCode, HttpWebResponse resp, T retVal, StorageCommandBase`1 cmd, Exception ex)
       at Microsoft.WindowsAzure.Storage.Blob.CloudBlobSharedImpl.<DeleteBlobImpl>b__1b(RESTCommand`1 cmd, HttpWebResponse resp, Exception ex, OperationContext ctx)
       at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult getResponseResult)
       --- End of inner exception stack trace ---
       at Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult`1.End()
       at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.EndDeleteIfExists(IAsyncResult asyncResult)
       at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass1`1.<CreateCallback>b__0(IAsyncResult ar)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.ServiceBus.Messaging.BlobLeaseManager.<DeleteAllAsync>d__2a.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.ServiceBus.Messaging.EventProcessorHost.<InitializeAsync>d__4.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.ServiceBus.Messaging.EventProcessorHost.<StartAsync>d__e.MoveNext()
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
       at System.Threading.Tasks.Task.Wait()
    at awaiteventProcessorHost.RegisterEventProcessorAsync<eventProcessor>();
    If we got the Exception, we won’t got messages any more.
    From the Call Stack, we found it was cause by delete the Blob. So we wonder that, when we call
    RegisterEventProcessorAsync,
    the hub will delete the blob and renew one in Storage?
    If we delete the blob for the EventHub manually and then run our server again. It worked as usual.
    But we can do it like this way manually, so is there any way to handle the exception in code to make the EventProcessorHost worked?
    Thanks so much!

    If we use different blob container name for different EventProcessorHost, is it a workaround for the issue?
       var
    eventProcessorHost = new
    EventProcessorHost(
                    hostName,
                    hubName,
                    consumerGroupName,
                    serviceBusConnectionString,
                    storageConnectionString,
    leaseContainerName);

  • How to handle SYSTEM_NO_MEMORY exception

    Hello,
    is there a way to handle the SYSTM_NO_MEMORY exception in a Z-Program? I want to show the user an error message with hints how to prevent this short dump instead of having the system showing the short dump.
    I tried to use TRY-statement but until now I wasn't successful.
    Thank you for your help,
    Stefan

    Hi Stefan;
    It seems there is no way to handle that exception as it's memory problem during run time.
    Please try to free unusable internal tables in each subroutine.
    Regards
    Vindy

  • Correct way to use SSL?

    I have just implemented a SSL certificate on my site. By
    default, site
    striucture is such that I have a HTTPDocs foder where I keep
    all my web
    pages etc but I also have a HTTPSDocs folder which is empty.
    The HTTPSDocs folder appears to be a mirror of the HTTPDocs
    folder, in that
    I do not need to manually put webpages that I wish to be
    secured into the
    HTTPS folder. In fact if I put the pages I want to be secured
    in the
    HTTPSDocs folder then the browser cannot find these pages.
    So, I have left all the pages etc. in the HTTP folder and for
    the pages I
    want secured I have linked from the form on the previous page
    by the full
    name eg. https://www.mysite.com/securepage.asp instead of
    just
    ../securepage.asp as it was before and this works fine. To
    leave the
    security I do the opposite eg.
    http://www.mysite.com/exitsecurepage.asp
    and
    this takes the browser back to a non-secured state. (the
    above links are
    dummy links)
    Is this the correct way to handle SSL?
    Thanks.

    Well, Is it???
    "GrantB" <[email protected]> wrote in message
    news:f0vieu$eeh$[email protected]..
    >I have just implemented a SSL certificate on my site. By
    default, site
    >striucture is such that I have a HTTPDocs foder where I
    keep all my web
    >pages etc but I also have a HTTPSDocs folder which is
    empty.
    >
    > The HTTPSDocs folder appears to be a mirror of the
    HTTPDocs folder, in
    > that I do not need to manually put webpages that I wish
    to be secured into
    > the HTTPS folder. In fact if I put the pages I want to
    be secured in the
    > HTTPSDocs folder then the browser cannot find these
    pages.
    >
    > So, I have left all the pages etc. in the HTTP folder
    and for the pages I
    > want secured I have linked from the form on the previous
    page by the full
    > name eg. https://www.mysite.com/securepage.asp instead
    of just
    > ../securepage.asp as it was before and this works fine.
    To leave the
    > security I do the opposite eg.
    http://www.mysite.com/exitsecurepage.asp
    > and this takes the browser back to a non-secured state.
    (the above links
    > are dummy links)
    >
    > Is this the correct way to handle SSL?
    >
    > Thanks.
    >

  • Is there a recommanded way to handle Microsoft.ServiceBus.Messaging.ReceiverDisconnectedException?

    In our Cloud Service project, we have 2 instances for work role (deploy to Azure), the work role is consume events from the EventHub using EventProcessorHost(host name is RoleInstance name), we send 100 events(event1~event100) to the EventHub, but some time
    we will got the Exception:
    Microsoft.ServiceBus.Messaging.ReceiverDisconnectedException: A receiver with epoch '3' already exists. A new receiver with epoch 1 cannot be created. TrackingId:5d3f5ed9-c397-42c6-8b9f-5f8f8f904131_G13_B13,TimeStamp:3/4/2015
    2:16:33 AM TrackingId:48438925-b879-4b20-b696-2b4fc3066a13_B13, Reference:b158c7f8-917e-4b24-a6f9-2a63e0af4bb9, Timestamp:3/4/2015 2:16:33 AM
       at Microsoft.ServiceBus.Common.ExceptionDispatcher.Throw(Exception exception)
       at Microsoft.ServiceBus.Common.Parallel.TaskHelpers.EndAsyncResult(IAsyncResult asyncResult)
       at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.<CallTask>b__9(TIteratorAsyncResult thisPtr, IAsyncResult r)
       at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
    the 2 instances will got the same event(like event25) when we got the exception, so is there a recommended way to handle the exception or do not occur the exception?

    You don't need to worry for the exception, it's part of the partition move process from one host to another. When partition ownership changes from host to another new host will start receiving from last check point as expected. So you can expect to see
    some duplicates when this happens. The question is that how frequently you're seeing partition ownership changes.

  • Catching exception from inherited constructor

    Hi all,
    If I'm extending a class and the constructor of the parent class throws an exception, is there any way to catch that exception in my constructor? What I would like to do is something like this.
    public class MyClass extends OtherClass {    // the constructor for OtherClass throws an exception
        public MyClass() {
            try {
                super();
            } catch (Exception e) {}
    }But of course you can't do that because super() has to be the first command in the method. Is there any other way to accomplish this? My objective is to chain this exception to a different type of exception.

    Write a factory method? For example:
    class ABCException extends Exception {}
    class XYZException extends Exception {}
    class OtherClass {
        public OtherClass()  throws ABCException {
            throw new ABCException();
    class MyClass extends OtherClass {    // the constructor for OtherClass throws an exception
        protected MyClass() throws ABCException {
           super();
        public static MyClass instance() throws XYZException {
            try {
                return new MyClass();
            } catch (ABCException e) {
                throw new XYZException();
    }

  • Is there a way to handle custom java exception in OSB?

    For example, i created a exception that extends RuntimeException.
    My exception has a new field called "code".
    I want to handle this exception in Oracle Service Bus process and retrieve this code to throws another exception with a XML structure that includes the code.
    Is there a way to do that ?
    <con:fault xmlns:con="http://www.bea.com/wli/sb/context">
         <con:errorCode>BEA-382515</con:errorCode>
         <con:reason>Callout to java method "public static org.apache.xmlbeans.XmlObject ...</con:reason>
         <con:java-exception xmlns:con="http://www.bea.com/wli/sb/context">
             <con:java-content ref="jcid:33a6c126:14006f3df18:-7fd9"/>
         </con:java-exception>
         <con:location xmlns:con="http://www.bea.com/wli/sb/context">
             <con:node>optmusPipeline</con:node>                    
             <con:pipeline>optmusPipeline_request</con:pipeline>
             <con:stage>processStage</con:stage>
             <con:path>request-pipeline</con:path>   
         </con:location>
    </con:fault>
    it is not enough to recover the information i needed.

    Hi Sandro,
    I've got the same situation. I agree that returning xml from function is not a best choice as you have to manually check if return status is an error or not. Processing exception in error handler is better and this is how I do it:
    I am doing a java callout to a function that can throw exception. Then I add ErrorHandler to stage containing this callout (all the exception are caught here).
    In the error handler I check if $fault/ctx:java-exception is not null. If not then I pass thrown exception to my utility function that converts it to xml similar to yours:
    import org.apache.xmlbeans.XmlException;
    import org.apache.xmlbeans.XmlObject;
    public static XmlObject exceptionToXML(Throwable exception)
      throws XmlException {
      String xmlString = exceptionToString(exception);
      return XmlObject.Factory.parse(xmlString);
    public static String exceptionToString(Throwable exception) {
      String cause = "";
      if (exception.getCause() != null) {
      cause = exceptionToString(exception.getCause());
      return String
      .format("<exception><name>%s</name><description>%s</description>%s</exception>",
      exception.getClass().getName(), exception.getMessage(),
      cause);
    Calling exceptionToXML with $fault/ctx:java-exception/ctx:java-content returns:
    <exception>
         <name>pl.app.MyException</name>
         <description>Exception message</description>
    </exception>
    Then you can check the exception class (IF action: $exception/name/text() = "pl.app.MyException") and handle it accordingly.
    Good luck,
    Krzysiek

  • Best way to handle any knid of exception

    Hi Experts,
    What is the best way to handle any kind of Exceptions across the layer and show a user friendly error message, for eg the JBO 2900, which is an unexpected error. There is no clue as to this error happens at which layer so how an we handle these kind of exceptions ?
    thnks

    hey you can try.. to add the exception handler.. in the task flow.. and in the DataBidnings.cpx..
    error from the controller can be got from
    ControllerContext context = ControllerContext.getInstance();
    ViewPortContext currentRootViewPort = context.getCurrentRootViewPort();
    Exception exceptionData = currentRootViewPort.getExceptionData();
    if (currentRootViewPort.isExceptionPresent()) {
    exceptionData.printStackTrace();
    currentRootViewPort.clearException();
    //FacesContext facesContext = FacesContext.getCurrentInstance();
    //facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, exceptionData.getMessage(), null));
    and the ui message can be thrown by
    FacesContext ctx = NavigationUtil.getFacesContext();
    FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR,message,null);
    ctx.addMessage(null, fm);

Maybe you are looking for

  • What is difference between Documanage and Documaker?

    Guys.. We are new to ECM, one of our customer is using both Documaker(Distributed) and Documanage for their vendor document management. So just I would like to know what would be the reason to use both? Instead can they use only documaker? Thanks in

  • Report is not displayed in xml format.

    Hi, We have a test station based in teststand 4.1 and labview 8.6 code modules. From one day to another, the xml report is blank, no character is displayed. That in Operator interface or sequence file execution in teststand editor.If the report forma

  • Sporadic Error in XLMP

    I get the following error (sporadically) when submitting a XML Publisher Report. Sometimes it works and other times it doesn't... totally random behavior. XML Report Publisher 5.0 Updating request description Waiting for XML request Retrieving XML re

  • Problem in loading images when i am connected on company network

    Hi friends, I am using firefox since last 4 months on my windows 8 pro laptop.but since last month I am facing problem in loading images when i am connected on company network but same time it is working fine with ie10. But all these thinks are worki

  • Issues with exporting quicktime

    I was recently able with the help of this forum to take my 4:3 footage and put it into a 16:9 sequence and crop it to look good. When it plays it looks fine. I then export using the quicktime conversion and select ntsc 16:9 but when it plays back fro