Throwing an exception within a catch

Hi all, I have a situation were I have a nested catch situation I would like to throw an exception within a catch and not catch it in my catch(Exception)
eg
try{
catch(exceptiontypeB e)
throw excetionTypeA
catch(exceptiontypeC e)
throw excetionTypeA
catch(Exception e)// the general exception, I dont whant to handel excetionTypeA from the other catch statements
throw excetionTypeA
please help cheers and thanx

try {
   // Do something
catch (SpecialException foo) {
  throw new ExceptionNotToBeCaught();
catch (Exception e) {
   if (e instanceof ExceptionNotToBeCaught == false) {
          // Process all exceptions here. 
         //  ExceptionNotToBeCaught will be ignored
}- Saish
"My karma ran over your dogma." - Anon

Similar Messages

  • Catching an exception within a JSP

    Hi all,
    I need to catch an exception in a JSP before the errorPage handles it. Have tried with try-catch but it seems like the exception is thrown to the errorPage anyway. Do you know of any technique to handle this.
    In other words: I would like to specify program logic for one exception within the JSP itself. Let us say Customer.Authenticate() throws an Exception when the given e-mail is not included in customer-DB. I would like to append logic instead of being redirected to errorPage.
    Anyone done this, can it even be done?
    ,Chr

    I would try keeping the error page as it is and still adding the logic in the catch block. If that does not help, then remove the error page and use <jsp:forward> (after your logic) in the catch block to explicitly go to the error page.
    or if you want to process that logic anyways in case of an exception, try adding your logic in the finally block.

  • I can throw exception from a catch

    Hello,
    I have created a new Exception : myException (for example).
    and, i can't throw it under a catch bloc !!
    My code :
    public myMethod( ... ) throw myException {
         try {
              if(true) thorw new NullPointerException("test nll pt");
         } catch(NullPointerException nullPt) {
              if(true) throw new myException("toto",nullPt.getMessage());
    this code doesn't want to throw "myException" from the "catch" !
    Why ?
    myException extends the class Exception.
    Thanks.
    maxx.

    First, I assume you didn't cut and paste the code, as what you have there won't compile. Can you 1) paste the actual code and 2) be a bit more specific about what's happening?
    Aside from a couple of misspellings, I don't see why it wouldn't throw myException. Is it not compiling? Running but not throwing any exception? Throwing a different exception?

  • Throw Soap Exception in BPM.

    Hi All,
    My scenario is Soap->XI->BPM->RFC. I get a soap request in synchronous way with Request and Response messages I Map my request to a RFC and If there's any application error or mapping error I have to send SOAP fault exception to my Soap Sending system. But I don't see any option in BPM to throw soap exception only thing I can do is to map my errors in the soap response and send it to soap sender.
    But my Soap sending system needs soap fault not a response message when any errors happen.
    Please let me know if anybody has this same situation and how to handle it.
    Thanks in Advance,
    SP.

    Hi VJ,
    I have to use BPM as I am doing other stuff in my BPM. In my BPM I am catching mapping exception and then I have to send this to Soap Sender in SOAP fault message and in abstract interfaces we don't have option to give fault message types. Also, I am using S/A bridge and I have to close the brige in order to send some response to Soap Sender.
    Is it possible to send soap fault when we close the S/A brige by send step.
    Thanks,
    SP.

  • Throwing Runtime Exceptions from BPM. How?

    Hi !
    I want to make appear a red flag in the SXMB_MONI as a result of a custom condition inside a BPM. I tried with the control step, but it makes no "red flag".
    Should I make a transform step between 2 dummy message types with a UDF that throws the runtime exception there?? is there another way ?? We want a red flag as a result of a expired deadline while waiting a file adapter transport acknowledgement.
    Thanks !!
    Matias.

    Matias,
    As you said before you want the BPM to be errored out if it reach the deadline, am I right. In control step if u say cancel process it equivalent to logically deleting the work items, so obviously you will get an succesfull message. What I suggest you to do is in  Deadline branch - control branch select throw exception. The exception name has to be defined in Block level. So if you throw an exception it will look for the exception branch in the same block level if not the higher(super)block level, if it couldn't find the exception branch it will run out to error. Actually the exception branch is used to catch that exception and continue the rest of the process, so i think there is no need for defining the exception branch itself.
    Hope it helps you!!!
    Best regards,
    raj.

  • Class.forName() throws null exception in servlet

    Hi, just wondering if anyone having this similar problem:
    when i try to load a class using Class.forName() method inside a servlet, it throws null exception.
    1) The exception thrown is neither ClassNotFoundException nor any other Error, it's "null" exception.
    2) There's nothing wrong with the code, in fact, the same code has been testing in swing before, works perfectly.
    3) I have include all necessary jars/classes into the path, even if i haven't, it should throw ClassNotFoundException instead, not "null" exception.

    I have tried to detect any possible nullable variable, and it is able to run until line 15. The exception thrown is actually null only... not NullPointerException... which is why i have confused...
    the message i received is "PlugInException: null".
    The code is at follow:
    * Load plugin
    * @return ArrayList of plugins
    * @exception PlugInException PlugInException
    01 public ArrayList loadPlugin()
    02 throws PlugInException
    03 {
    04 PlugIn plugin;
    05 ArrayList plugins = new ArrayList();
    06
    07 for (int i = 0; i < configLoader.getPluginTotal(); i++)
    08 {
    09 try
    10 {
    11 if (debugger > 0)
    12 {
    13 System.out.print("Loading " configLoader.getPluginClass(i) "...");
    14 }
    15 if (Class.forName(configLoader.getPluginClass(i)) == null)
    16 {
    17 if (debugger > 0)
    18 {
    19 System.out.print(" not found");
    20 }
    21 }
    22 else
    23 {
    24 if (debugger > 0)
    25 {
    26 System.out.println(" done");
    27 }
    28 plugin = (PlugIn)(Class.forName(configLoader.getPluginClass(i)).newInstance());
    29 plugin.setContainer(container);
    30 plugins.add(plugin);
    31 }
    32 }
    33 catch (Exception e)
    34 {
    35 throw new PlugInException("PlugIn Exception: " + e.toString());
    36 }
    37 }
    38
    39 return plugins;
    40 }

  • How to throw bundled exceptions thrown by checkErrors()

    Hi,
    I call pl/sql to do update, and call checkErrors() , the code looks like following, but it doesn't display read friendly message on the screen. What is the right way to throw bundled exception from checkErrors() method?
    try{
    xxg2cGoalPk.startWf (conn,
    new BigDecimal(srpGoalHeaderId),
    new BigDecimal(userId),
    returnStatus,
    msgCount,
    msgData);
    int msgCount1 = 0;
    if(msgCount[0] != null){
    msgCount1 = Integer.parseInt(msgCount[0].toString());
    String returnStatus1 = returnStatus[0];
    String msgData1 = msgData[0];
    OAExceptionUtils.checkErrors(tx,msgCount1, returnStatus1, msgData1);
    catch(OAException e) {
    e.printStackTrace();
    throw new OAException(e.getDetailMessage(),OAException.ERROR);
    thanks
    Lei

    What Shiv said is only an alternative, but what you are using is correct.I haven't tested but as per javadoc of
    OAExceptionUtils.checkErrors(tx,msgCount1, returnStatus1, msgData1);
    will itself raise bundled exceptions. You need to write this line outside try/catch block.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to Throw an Exception in a SapServer

    Hello,
    We have successfully implemented SAPServer in our external process.
    The only thinks that doesn't work perfectly is that we can't throw an exception in the implementation of remote function module.
    The ABAP Program that is calling our fontion waits on expetion 0, 1, 2, 3 and 4. But when we throw the exception like this : throw new RfcException( "Error" );
    the ABAP catch this exception, but as exception 4 (others) and not as 3 (Error)
    Can someone help. Thanks

    Hello
    Thanks for the answer.
    In the while we tried the following:
    RfcAbapException( "ERROR" );
    but it doesn't work.
    The solution was to call this method with 2 parameters:
    RfcAbapException( "ERROR", "Some error text...");
    And now OK.

  • Performance costs of throwing an Exception

    Hi people. I was just reading another post around here, and I became curious about how much the Exception mechanism could become an overhead... I made a simple (REALLY simple) little test class, and I was shocked to perceive that actually throwing an Exception is cheap (I always thought that it would be just the opposite...). Try running this later:
    public class Test {
         public boolean something() {
              return true;
         public void nothing() throws Exception {
              throw new Exception("Voila");
         static public void main(String[] algo) {
              Test test = new Test();
              long now = System.currentTimeMillis();
              test.something();
              System.out.println("boolean method took " +
    (System.currentTimeMillis() - now) + " milliseconds.");
              now = System.currentTimeMillis();
              try {
                   test.nothing();
              } catch (Exception e) {
                   System.out.println("exception method took " +
    (System.currentTimeMillis() - now) + " milliseconds.");
    }and here are some results I got:
    1)
    boolean method took 0 milliseconds.
    exception method took 0 milliseconds.
    2)
    boolean method took 0 milliseconds.
    exception method took 0 milliseconds.
    3)
    boolean method took 0 milliseconds.
    exception method took 0 milliseconds.
    Of course, I assume that when the stack grows a bit, the result could be quite different. I ran this on a AMD 900 MHz, 512Mb RAM, JDK 1.4.1_01 under Eclipse.
    PS: Excuse me for my bad English :)
    falowwwwww

    Yeah, I guess I was always right...
    Here's the (fixed) code:
    public class Test {
         public boolean something() {
              return true;
         public void nothing() throws Exception {
              throw new Exception("Voila");
         static public void main(String[] algo) {
              Test test = new Test();
              long now = System.currentTimeMillis();
              for (int i=0; i<Integer.MAX_VALUE; i++) {
                   test.something();
              System.out.println("boolean method took " + (System.currentTimeMillis() - now)
                   + " milliseconds.");
              now = System.currentTimeMillis();
              for (int i=0; i<Integer.MAX_VALUE; i++) {     
                   try {
                        test.nothing();
                   } catch (Exception e) {
              System.out.println("exception method took " + (System.currentTimeMillis() - now)
                   + " milliseconds.");
         }The boolean loop took twelve seconds to finish... The exception loop ran for almost 18 minutes (when I stopped it! it didn't even complete!)
    If anyone want to, run the code and post here the real results. Thanks!!
    I guess that "our great designers" here at my company will lose their jobs... Well I think they deserve it. If only they payed attention to me at the beggining when I complained about throwing lots of unnecessary exceptions... eheheheh
    PS: Excuse me for the bad English again!!
    falow!!!!!!!

  • Throwing an Exception

    I have a class for adding special datatypes. Within this class I have a check to test whether or not the two objects can be added. If they cant be added I want to throw an exception (i think). How would I do this.

    throw new IllegalArgumentException("can't add the types!");Or you could create your own RuntimeException.

  • How should i know which exception should i catch?

    hey all....
    i am getting the following error msgs (everything is compiled just fine..)
    I successfully translated the word car to &#945;&#965;&#964;&#959;&#954;&#943;&#957;&#951;&#964;&#959;
    15 &#916;&#949;&#954; 2006 5:28:40 &#956;&#956; com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl <init>
    WARNING: "IOP00410201: (COMM_FAILURE) Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: 10.34.153.11; port: 1541"
    org.omg.CORBA.COMM_FAILURE:   vmcid: SUN  minor code: 201  completed: No
         at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(Unknown Source)
         at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(Unknown Source)
         at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(Unknown Source)
         at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(Unknown Source)
         at com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl.createConnection(Unknown Source)
         at com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(Unknown Source)
         at com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.request(Unknown Source)
         at org.omg.CORBA.portable.ObjectImpl._request(Unknown Source)
         at WorkflowFramework._ServiceStub.translationService(_ServiceStub.java:18)
         at wF.ServantEnglishToGreek.translationService(ServantEnglishToGreek.java:294)
         at WorkflowFramework._ServiceImplBase._invoke(_ServiceImplBase.java:41)
         at com.sun.corba.se.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(Unknown Source)
         at com.sun.corba.se.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(Unknown Source)
         at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(Unknown Source)
         at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(Unknown Source)
         at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleInput(Unknown Source)
         at com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(Unknown Source)
         at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(Unknown Source)
         at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.dispatch(Unknown Source)
         at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.doWork(Unknown Source)
         at com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(Unknown Source)
    Caused by: java.net.ConnectException: Connection refused: connect
         at sun.nio.ch.Net.connect(Native Method)
         at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
         at java.nio.channels.SocketChannel.open(Unknown Source)
         at com.sun.corba.se.impl.transport.DefaultSocketFactoryImpl.createSocket(Unknown Source)
         ... 19 more
    NEXT SERVER IS DOWN! org.omg.CORBA.COMM_FAILURE:   vmcid: SUN  minor code: 201  completed: No when i am running a function on a remote object reference
    i have catched the exception and that is why the msg NEXT SERVER IS DOWN is printed..but how can i handle all the previous msgs?
    i searched a lot on the internet and i cannot find how to catch this error...
    all these msg seem to come from the java.net.ConnectException: Connection refused: connect but i dont have any statement that i can include in a catch try block so that i can do sth with that..(maybe print a msg..)
    btw the line from my code that this msg is refering to is the following
    try{
         //call next server
            nextServerRef.translationService(objRef, buffer);
    //      catch(java.net.ConnectException e){
    catch(Exception e){
              System.out.println("NEXT SERVER IS DOWN! "+e);
               }and btw i cannot include this code to the ConnectException because it keeps complaining that this code cannot throw this exception....
    any advice????
    ps.i have posted a specific msg to the rmi subforum...but i am trying to undestand the general process ..to look the wood not the trees;-)

    If the runtime exception occurs in a method that doesn't either catch it or declare it as being thrown, and you can't change the method, then there's not much you can do except diverting the output to a non-visible location, or a null sink.
    If you can change the method, you can either catch the exception and substitute your message, or you can change it to throw the method, and then catch the exception in a higher enclosing method, as I show:
    public static void main(String[] args)
        try
            some_method();
        catch (ConnectException ce)
            System.out.println("NEXT SERVER IS DOWN");
    static void some_method() throws ConnectException
        throw new ConnectException(); // create the exception
    }

  • Catch exceptions out of catch block

    Hello,
    Here in my job we was using Log4J , but since some of our logs need complex things like replication for
    some databases analise log t see where we will send in and lots of emails too , so we are developing our own log framework, my question is , there is a way to caught exceptions not declared in a try catch block?
    Example: IndexOutOfBound some time are not cought in a try catch block, or some files sometimes came null and throws uncauht exceptions some times, there is a way to me listen to all execptions wich was throwed to the system and have a no catch block??
    Thank You
    Ricardo

    When an uncaught exception occurs, the JAVA runtime system determins the ThreadGroup of the current thread and calls "uncaughtException" on that ThreadGroup object. However, the java.lang.ThreadGroup object performs the printing of the stack trace, which you will normally see in such cases.
    If you want to modify this behaviour, you could write your own ThreadGroup class, which extends java.lang.ThreadGroup and provides a different implementation of uncaughtException. E.g. you could write a log message to your own log file or whatever you want.
    Now you must guarantee, that all threads in your system are childs of that customized ThreadGroup. I did this in my main class:
    public class Application implements Runnable {
        private String[] argv;
        public static void main(String[] argv) {
            this.argv = argv; // save this for use in the run method
            ThreadGroup tg = new MyThreadGroup();
            // start a thread in the new thread group and terminate the original main thread
            new Thread(tg, this, "main").start();
        public void run() {
            // perform all other tasks here
    public class MyThreadGroup extends ThreadGroup {
        public MyThreadGroup()  {
            super("MyThreadGroup");
        public void uncaughtException(Thread thread, Throwable exception) {
            // ignore death of thread
            if (exception instanceof ThreadDeath)
                return;
            // ---- perform your actions here ----
    }All other threads, which are created later, are also in the new thread group, because they inherit the group from their creator.

  • While opening firefox or any page adialogue box appear " [java script application] An error occured throwing an exception" -what to do

    i am using vista sp1, recently while opening Firefox or any link within it a dialogue box appear " [java script application] An error occured throwing an exception" . however both cancelling or accepting opens the link or firefox but its nagging plz help
    == This happened ==
    Every time Firefox opened
    == few days ago

    The code is not working because you made a mistake somewhere, duh! So figure out what (hint: firefox javascript console, it's your friend) and fix it!
    And next time when you post code: use the [ code ]  tags to pretty format your code, as it is now it's unreadable.
    http://forum.java.sun.com/help.jspa?sec=formatting

  • GetBlobReferenceFromServerAsync (and non-async) throw an exception with 404 (not found) if the blob doesn't exist.

    I'm trying to determine if a particular file exists in a blob store. I'm using container.GetBlobReferenceFromServerAsync and if the named blob does't exist I get an exception with a 404. ICloudBlob (which is returned by the method) defines an Exists method
    but it's functionally useless because the GetBlobReferenceFromServerAsync method call itself throws the exception. I do get the behavior I'm looking for if I call container.GetBlockBlobReference instead but there's no async version of that method.

    As I said I'd found that GetBlockBlobReference works but there's no async version of that method. I'm trying to determine IF a blob exists not create one. Since the GetBlobReferenceFromServer returns an ICloudBlob and ICloudBlob defines and Exists method
    you'd assume that it could be used to determine if a blob exists. I'd argue that the fact that it throws and exception when the blob does not exist is a bug in the implementation because it makes the Exist method on the ICloudBlob object functionally useless.
    Also, it seems like a fairly significant miss that there's no async version of GetBlockBlobReference. A query to a cloud resource is exactly the perfect use case for the async/await pattern.
    Does anyone know of an async way to check for the existence of a blob that doesn't involve catching a 404 exception?

  • 2 connections, either one can throw an exception

    In my application I have 2 connections open to the different DBs at the same time. Either operation ( select/update etc ) can throw an exception. I don't want to embrace every SQL statement with the different "try ... catch" block, because it will be too messy. Is there any way to determine what connection threw an exception.
    Sample :
    try{
    Connection conn1 = ...
    Connection conn2 = ...
    PreparedStatement ps1 = conn1.getPreparedStatement(...);
    PreparedStatement ps2 = conn2.getPreparedStatement(...);
    ps1.executeQuery(qstring1);
    ps2.executeQuery(qstring2);
    catch ( SQLException ex){
    // Can I put some logic here which will tell me whether the problem related to conn1 or conn2 ?
    System.out.println("Exception : " + ex);
    }

    vs777 wrote:
    I have a "global" DB instance where my metadata and instance-specific data resides ( domestice data ). I also have "secondary" DB instance with ( foreign data ) to which I might connect at the run-time if the application logic requires. I am updating metadata Sounds like you want to do "change data capture". If that's the case, I'd recommend looking into your database vendor's capabilities rather than doing this in Java. I'd also look into database links and triggers if your database supports them. Sounds like you're doing something that's best left to the database, not your application. It could be done behind the scenes. It sounds like more of a pure database play rather than business logic.
    throughout the application "metadata"? What does that word mean to you? Please explain.
    So you're changing the schema dynamically? Metadata means describing the tables and columns. That's changing as the app runs? Sounds confusing.
    as well as retrieve and update data in one of the instances depending on conditions, so it's really inconvinient for me to wrap every SQL statement ( execute/select/delete method ) with "try ... catch" block.Inconvenient, but necessary. Somebody has to handle exceptions.
    Sounds like you need to think about a way to not repeat code.
    I have an application up-and-running for several months already and "2 DB instances" requirement came up just recently, so I am not planning to redesign an application but to handle SQL exceptions properly.So what do you want here? What are you asking if you're not willing to redesign anything?
    You're probably not even aware of two phase commit. What happens to your app if the insert of the data succeeds but the metadata does not? Ooops, out of synch. Do you roll back manually? How does the app alert you to the need to do so?
    %

Maybe you are looking for

  • Add file name script not working in CS3

    I have this wonderful script (written by Brian Price) back in 2004 for PS7 that adds the file name to an image ( I use it for adding file names to small images to be used in a slideshow). It works great ion Photoshop CS, but when I try to use it as p

  • XA error while using TxConnectionPool

    Sometimes I get the following error message when invoking a database methode inside a stateless session bean: "java.sql.SQLException: XA error: XAER_PROTO : Routine was invoked in an inproper context start() failed on resource 'mdmPool' start failed

  • 10.4.11 update troubles

    OK, so I updated to 10.4.11. 1st thing that happens is Safari doesn't work anymore--spontaneously quits immediately after opening. Now I can't even install software I've downloaded to try to solve this problem, for example the Combo update I got from

  • Error message = [\dev\stingray\Libraries\Asl\Foundation\Src\DirectoryRegistry.cpp-174] plz help.

    I have CS2 (education version) and my Premier Pro 2.0 gives me the following error when i try to load it: \dev\stingray\Libraries\Asl\Foundation\Src\DirectoryRegistry.cpp-174 and will not load. All other CS2 applications are working. This program was

  • SCM and PI - ALE configuration

    Hi, I  need to set up ALE config between an SCM and PI system. Please guide me with the steps and procedure. Till what step BASIS has to take care and what are all to be completed by ABAPer/Functional Kindly guide me with the steps. Thanks in advance