Can synchronized( someObj ) ever throw an exception?

I know that object.wait() can throw an exception (IllegalMonitorStateException or InterruptedException) can synchronized ever do the same?
For example:
synchronized( obj ) //does this line ever throw an exception?
}What is that synchronized line in byte code?

[Section 14.19 of the Java Language Specification|http://java.sun.com/docs/books/jls/third_edition/html/statements.html#255769] says that if the value of obj is null, then a NullPointerException is thrown.

Similar Messages

  • Can a singleton contructor throw an exception?

    Topic says it all.
    Superclass throws an exection, so trying to create an instance as a class member is falling over.

    To avoid double checked locking, synchonize on the initialize and fire this in your main method.
    Then access to the getInstance() can be unsynchronized and failure to initialize is very evident at program startup.
    public class SuperClass
      public SuperClass() throws Exception
    public class MySingleton extends SuperClass
      private static MySingleton instance = null;
      private MySingleton() throws Exception
        super();
      public static synchronized initialize() throws Exception
        if (instance != null)
          throw new IllegalStateException("MySingleton is already initialized");
        instance = new MySingleton();
      public MySingleton getInstance()
        if (instance == null)
          throw new IllegalStateException("MySingleton not initialized");
        return instance;
    }I think your class SuperClass() throws Exception {}; is a typo

  • Can a static constructor throw an exception?

    Or is it not possible?

    If you throw a checked exception from an initializer
    it won't even compile. There's no trying about it.From a static initializer. A non-static initializer, via the spec, is supposed to allow this. Although Sun VMs previous to 1.4 did not allow it due to a bug....
    http://forum.java.sun.com/thread.jsp?forum=4&thread=198991

  • 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?
    %

  • I can't throw my exception

    I created my exception
    public class wyjatek extends Exception {
        public wyjatekNieobslugiwany() {
    }i can throw him in my code:
       try{
                                    try{
                             x= request.getParameter("x");
                             y= request.getParameter("y");
                        } catch (NullPointerException npe){
                             throw new wyjatek();
                                    if (x.equals(y)){
                                        out.println('equal')
        } catch (wyjatek w){
        }but i have NullPointerException. Code after throw new wyjatek() is executing.
    Why?
    I change line "throw new wyjatek()" to "throw new Exception()" and everything was fine. Why I can properly throw Exception() but I can't throw wyjatek() witch extends Exception()?

    but i have NullPointerException. Code after throw new wyjatek() is >executing.Wrong, that's the code throwing NPE.
    try{
         //A NPE Exception will never be thrown here
           x= request.getParameter("x");
          y= request.getParameter("y");
    } catch (NullPointerException npe){
          throw new wyjatek();
    if (x.equals(y)){ //this is where NPE will be thrown if x or y is null
         out.println('equal')
    }For your exception to be thrown (cant figure out why you should throw CustomExceptions on NP, though)
          x= request.getParameter("x");
          y= request.getParameter("y");
          try{
                     if (x.equals(y)){
                         out.println('equal')
              }catch(NullPointerException npe){
                   throw new wyjatek(npe.getMessage());
          }cheers,
    ram.

  • 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.

  • Limit the time of lookup and make the method to throw an Exception

    When I connect from
    Client
    Remote Desktop Client
    Server:
    SUN JAVA SYSTEM APPLICATION SERVER 9.0
    Initial Context object is initialized as per below coding,
    System.setProperty("org.omg.CORBA.ORBInitialHost", prop.getProperty("hostName"));
    System.setProperty("org.omg.CORBA.ORBInitialPort", prop.getProperty("portNumber"));
    InitialContext ctx = new InitialContext();
    while .lookup("globalJndiNameForSessionBean") method is invoked on the InitialContext object and if the server is not available, it is throwing non stop error.
    Please tell me wether I have to add any other Properties to limit the time of lookup and make the method to throw an Exception after two or three second, if the server is not available.

    What do you mean by 'non-stop error'? This can only happen if your code goes into a non-stop loop.
    The default TCP connect timeout is about 75 seconds, which in some circumstances is too long, but two or three seconds definitely isn't long enough. Ten to twenty would be more like it.
    I'm not aware of any system properties that limit the ORB connect timeout but then I'm not aware where the existing J2SE ORB system properties are documented. If anybody has ever found this please let us know.

  • Throwing an exception from XSLT

    Just wanted to share a finding with the Oracle XDB community and possibly suggest an enhancement to the xdb product development team (care of MDRAKE).
    I had a scenario where I wanted to throw an exception from the XSLT.
    A little Googling revealed this helpful post:
    http://weblogs.asp.net/george_v_reilly/archive/2006/03/01/439402.aspx
    ...so I gave it a shot.
    In my XSLT, I have a <xsl:choose> block with the following <xsl:otherwise> block:
    <xsl:otherwise>
        <xsl:message terminate="yes">Unknown Document Type</xsl:message>                          
    </xsl:otherwise>I used a stub test to run this through, giving it a file which would exercise the exception:
    select xmltype(bfilename('XML_RESOURCES', 'data.xml'),0).transform(xmltype(bfilename('XML_RESOURCES', 'sanitize_xml.dev.xsl'),0))
    from dual;..and to my 'joy', I did get an exception:
    ORA-30998: transformation error: execution of compiled XSLT on XML DOM failedHmm...would of been nicer to get something like what Eclipse/Xalan pops out:
    file:/H:/eclipse_indigo_workspace/XSLT/sanitize_xml.xsl; Line #28; Column #59; Unknown Document Type
    (Location of error unknown)Stylesheet directed termination...i.e. my custom error message "Unknown Document Type" isn't output by Oracle.
    Just to be safe, I tried a file which would NOT exercise this xsl:otherwise block and it did run through OK.
    So, could XDB report a better error?
    Thoughts?

    SQL> VAR XSL VARCHAR2(4000)
    SQL> --
    SQL> begin
      2    :XSL :=
      3  '<?xml version="1.0" encoding="UTF-8"?>
      4  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      5     <xsl:output method="xml" indent="yes"/>
      6     <xsl:template match="/">
      7             <Result>
      8                     <xsl:choose>
      9                             <xsl:when test="Input=''1''">
    10                                     <Output>1</Output>
    11                             </xsl:when>
    12                             <xsl:when test="Input=''2''">
    13                                     <xsl:message>The value is 2</xsl:message>
    14                                     <Output>2</Output>
    15                             </xsl:when>
    16                             <xsl:when test="Input=''3''">
    17                                     <xsl:message terminate="no">The value is 3</xsl:message>
    18                                     <Output>3</Output>
    19                             </xsl:when>
    20                             <xsl:otherwise>
    21                                     <xsl:message terminate="yes">Invalid value</xsl:message>
    22                                     <Output>Bad Input</Output>
    23                             </xsl:otherwise>
    24                     </xsl:choose>
    25             </Result>
    26     </xsl:template>
    27  </xsl:stylesheet>';
    28  end;
    29  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> select XMLTRANSFORM(XMLTYPE('<Input>1</Input>'),XMLTYPE(:XSL))
      2    from dual
      3  /
    <?xml version="1.0" encoding="WINDOWS-1252"?>
    <Result>
      <Output>1</Output>
    </Re
    Elapsed: 00:00:00.01
    SQL> select XMLTRANSFORM(XMLTYPE('<Input>2</Input>'),XMLTYPE(:XSL))
      2    from dual
      3  /
    <?xml version="1.0" encoding="WINDOWS-1252"?>
    <Result>
      <Output>2</Output>
    </Re
    Elapsed: 00:00:00.00
    SQL> select XMLTRANSFORM(XMLTYPE('<Input>3</Input>'),XMLTYPE(:XSL))
      2    from dual
      3  /
    <?xml version="1.0" encoding="WINDOWS-1252"?>
    <Result>
      <Output>3</Output>
    </Re
    Elapsed: 00:00:00.01
    SQL> select XMLTRANSFORM(XMLTYPE('<Input>4</Input>'),XMLTYPE(:XSL))
      2    from dual
      3  /
    ERROR:
    ORA-30998: transformation error: execution of compiled XSLT on XML DOM failed
    no rows selected
    Elapsed: 00:00:00.01
    SQL>
    SQL>The actuall error is not unreasonalbe. The Execution did fail beacuse you terminated it.. Contacting Oralce Support may be a little excessive...
    Now with respect to message the question is where...
    We 'could' output into the same buffer as is used by DBMS_OUTPUT, but that has limits in terms of the amount of output that can be generated.
    We could write it to the trace file, but that may be difficulat for a developer to get to
    We could write it to a log file in the XDB repository, but where and how to name it...
    We could another parameter to XMLTransform, which would be a Message Buffer
    All of these are in effect enhancements..
    BTW I checked with XML Spy and they seem to ignore message too, so I'm wondering how widely used this is...
    We cannot add it to the output of the XSL since XMLTransform defines the output of the XML to be well formed XML, and adding a random set of text nodes would viloate that rule..

  • How to Throw/Catch Exceptions in BPM

    Hi All,
    I've seen a couple articles that talk about how to Throw/Catch an execption in a BPM. My question has two parts:
    1) RFC Call: I was able to catch an Fault Message in an exception step when calling an RFC (Synchronous Interface). What I wanted to do is use the fault message (exception) and store it in a DB for later review.
    2) IDOC: I'm sending an IDOC to R3 from a BPM. The send step is enclosed in a block w/ an exception. The send step is throwing an error (IDOC adpater system error), but the exception is never thrown. My question is: when the error occurrs at the adapter level does it still throw an exception in a BPM?
    Thanks for any tip/advice/anything!
    Fernando.

    Hi Fernando,
    1) Define a send step in the exception branch.
    2) If u send a IDoc from R/3 to XI and the IDoc adapter is running to an error of course there cant be an exception in ur business process. Usually the IDoc adapter sends back status back up via ALEAUD. In case of success IDoc should have then '03', if the adapter cannot send anything the IDoc should remain at '39'. U should send a ALEAUD in case of exception of BPM switching to status '40', in case of success to '41'.
    Regards, Udo

  • Export with BiarEngine.jar works, using the API it throws an exception

    Hello,
    I'm using BiarEngine.jar to export from my CMS. it works fine.
    Now I want to use the API to get someting more handy, but I receive an exception (NoSuchFieldError) as if I had a mismatch between versions.
    I'm stuck with it, if somebody has an idea...
    Thanks a lot.
    Alain
    Here is the java code:
    IExportOptions oExportOptions = BIARFactory.getFactory().createExportOptions();
    oExportOptions.setIncludeSecurity(false);
    oExportOptions.setIncludeDependencies(true);
    oExportOptions.setCallback(
         new IExportCallback()
              public void onSuccess(int id)      {...}
              public void onFailure(int id, BIARException biarException) {...};
    BIAROutput oBIAROutput = new BIAROutput( oEntrepriseSession, "c:\myFile.biar", exportOptions );
    At this point it throws the exception:
    Exception in thread "main" java.lang.NoSuchFieldError: SI_MODELCUID_SET
         at com.businessobjects.sdk.plugin.desktop.deltastore.internal.DeltaStore.setupProperties(DeltaStore.java:188)
         at com.businessobjects.sdk.plugin.desktop.deltastore.internal.DeltaStore.unpack(DeltaStore.java:37)
         at com.crystaldecisions.sdk.occa.infostore.internal.al.continueUnpack(Unknown Source)
         at com.crystaldecisions.sdk.occa.infostore.internal.al.startUnpack(Unknown Source)
         at com.crystaldecisions.sdk.occa.infostore.internal.InternalInfoStore.queryHelper(Unknown Source)
         at com.crystaldecisions.sdk.occa.infostore.internal.InternalInfoStore.query(Unknown Source)
         at com.crystaldecisions.sdk.occa.infostore.internal.at.query(Unknown Source)
         at com.businessobjects.sdk.biar.internal.XSDManager$RepositoryXSD.retrieveXSDVersions(XSDManager.java:204)
         at com.businessobjects.sdk.biar.internal.XSDManager$RepositoryXSD.<init>(XSDManager.java:194)
         at com.businessobjects.sdk.biar.internal.XSDManager$XSDCache.getXSD(XSDManager.java:365)
         at com.businessobjects.sdk.biar.internal.XSDManager.<init>(XSDManager.java:55)
         at com.businessobjects.sdk.biar.BIAROutput.<init>(BIAROutput.java:73)

    >
    Just need to confirm if the ANT script can be run against individual OSB project than OSB configuration project?
    >
    It is possible. I'm going the same way here. However, I remember I needed to contact support because it was not a standard feature of the Ant task. They provided me with the patch that allowed me to use -configSubProjects parameter in export.
    >
    Can we have multiple OSB configuration projects on the OSB server ?
    >
    I don't think so.

  • JNI Application running in ms-dos but throws an exception in applet

    Hi! I have a java application which calls a DLL using the JNI. This works perfect if I execute the java program from my command line (in ms-dos) But when I try to do it in an applet, it indeed runs and do everything ok, but at the end of the execution I get a EXECUTION_EXCEPTION.
    This is how is working:
    1.- jnidllmyclass, this is where I call the native method of my DLL
    2.- intermediate DLL which writes to files to c:\temporal and it calls several functions from other DLL
    3.- other DLL which writes more files (among other things)
    4.- applet class with a call to jnidllmyclass
    Now the DLL what does is to open a connection to a usb scanner, then send commands to it to scann somethings, save front and back images to c:\temporal (obviously, all of this is done in the user system, using certificates) and write other file and close the connection. This works! it write the images well and write everything... but after that the exception arises... I have doubt of what is it, because if it does all, what is causing the exception?
    Thanks for your help!

    Hi! Applet can access the DLL. The scanners works, but the C DLL throws an exception. Nevertheless, I've managed to see what was going on. When you click a JButton in a GUI, it enters only one to the actionlistener, but if this is done in an Applet, enters twice, so... the first time worked fine, but the second no because there was nothing to scann.
    This theme is a bit creepy, if you want help just ask! I give snippets, not just advices... I hate those people, so fell free to ask.
    Greetings!

  • FM used in background job throws an Exception-NO_BATCH

    Hi,
    I have one normal ABAP report with selection screen, where selection parameters are file names and they are used for uploading data from excel to internal table and then internal table to excel respectively.
    Now I want to put this as a background job. So I saved the variant and now while running the job there is an exception.
    Reason for the same as I could find out is:
    while uploading function module (KCD_EXCEL_OLE_TO_INT_CONVERT or ALSM_EXCEL_TO_INTERNAL_TABLE) is called, it has some front-end  services called.
    That is in case of first function module, it is CLPB_IMPORT which in turn calls WS_QUERY where GUI_EXIST is checked and there it throws an exception.
    And in the later case it is cl_gui_frontend_services class and its some method is called.
    So basically, frontend services are called in any case and I still want this as a background job.
    Can Anyone clear it conceptually?

    Hello Krupa,
    The rule is pretty much simple: <i>Anything that you do in batch / background, cannot have anything to do with the front-end / desktop.</i>
    The Excel sheet you use is an application that runs on the Frontend, right? So you cannot do it in batch. The reason, to put it crudely, is that a background job is run by a different workprocess altogether and that work process is not capable of accessing the front-end. Ideally, a background job should be run-able even without a GUI!!
    SO what you can do in a background job, is to operate on the files present on the application server (that is where the job runs).
    Hope that is clear. If not, get back.
    Regards,
    Anand Mandalika.
    Regards,
    Anand Mandalika.

  • 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.

  • 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.

  • Throwing generic exception in XI

    Hi friends
    I was trying to incorporate one of the blog by champion blogger Michal, which deals with Throwing Generic Exception.
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6398. [original link is broken] [original link is broken] [original link is broken] [original link is broken]
    Is there any way around for avoiding ABAP mapping (hard part) and implementing some java code in place of that?
    In second step instead of going for ABAP mapping I tried to raise an exception by using  exception classes as explained in   https://www.sdn.sap.com/pub/wlg/3069. [original link is broken] [original link is broken] [original link is broken] [original link is broken] but by that way Error in SOAP header (in SXMB_MONI) displayed Runtime Exception rather than showing user defined/desired message

    hi,
    just like explained in my blog - you can only do it in ABAP
    to have it in error header segment of XI message
    >>>>but by that way Error in SOAP header (in SXMB_MONI) displayed Runtime Exception rather than showing user defined/desired message
    just like Alex mentioned in his blog - that's why I wrote mine
    Regards,
    michal

Maybe you are looking for

  • Is there a way to make the view window on mail display messages with a larger size ?

    I would like to set it up as a default, and not have to zoom in or make larger (cmd +) each individual message. I have tried the font setup, but it does not work. It works for my own messages only. I guess what I'm asking is if the font-setup of the

  • Hierarchical  keywords, collections and XMP

    Hi,<br /><br />I tried to figure out how LR stores the hierarchical keyword tree in the XMP data. XMP data written by LR contains all the info to recreate the keyword hierarchy. While the keyword text strings are plain ascii, the keyword linking info

  • No posting in FI but still there are values in CX34?

    Hi, For period 2, 2011 there is no posting in FI (FS10N/FBL3n) but still we can find values in CX34 in EC_CS in group currency. Please can anyone help me on this? I have already checked cost center/proft center line items reports for that particular

  • IMovie '9 No export Option..? WHY?

    For the first time I used iMovie and made a nice clip that i must paly in an hour at my club and i try to export it. I went to the file menu and i see there is no Export Option... WHY is that??? i Got a big problem here.... plz Any help is More than

  • JAXB 2.0 Marshaling Exception

    Hello, I ran into an error when trying marshal a java class. NullPointerException is caught when this line of code is executed. I previously used XJC to generate the Java classes including ObjectFactory.java in textjaxb.student package. JAXBContext j