Can I throw exception in constructor?

I just want to add some constraints on the object.
I'm thinking to add the constraints to the constructor, when every time create a new object , check first. If obey the rule, that's fine. If not, just throw it? Can I do like this way??
e.g Class Distance
Distance(x){if x >= 0.0  dist = x  else throw...}
float dist;
}

The best exception to throw in that case is IllegalArgumentException..
class Distance {
    float dist;
    Distance(float x) {
        if (x < 0.0) {
            throw new IllegalArgumentException("x must be non-negative");
        dist = x;
}

Similar Messages

  • Custom Indirection Container throwing exception in constructor

    Hi I've following the how-to and implemented my own custom indirection container. However, when reading an object from the database I'm getting the following exception. I'm guessing that it could be related to having null references stored as 0 in id columns. Any help would be greatly appreciated.
    Thanks,
    Jon
    Exception thrown in main Exception [TOPLINK-152] (OracleAS TopLink - 10g (9.0.4.8) (Build 050712)):
    oracle.toplink.exceptions.DescriptorException
    Exception Description: The operation [buildContainer constructor (null) Failed: java.lang.NullPointe
    rException] is invalid for this indirection policy [oracle.toplink.internal.indirection.ContainerInd
    irectionPolicy@cc0e01].
    Mapping: oracle.toplink.mappings.OneToOneMapping[ryFromMail]
    Descriptor: Descriptor(com.peoplesoft.crm.omk.design.PsRyedocVar --> [DatabaseTable(PS_RYEDOC_VAR)])
    Local Exception Stack:
    Exception [TOPLINK-152] (OracleAS TopLink - 10g (9.0.4.8) (Build 050712)): oracle.toplink.exceptions
    .DescriptorException
    Exception Description: The operation [buildContainer constructor (null) Failed: java.lang.NullPointe
    rException] is invalid for this indirection policy [oracle.toplink.internal.indirection.ContainerInd
    irectionPolicy@cc0e01].
    Mapping: oracle.toplink.mappings.OneToOneMapping[ryFromMail]
    Descriptor: Descriptor(com.peoplesoft.crm.omk.design.PsRyedocVar --> [DatabaseTable(PS_RYEDOC_VAR)])
    at oracle.toplink.exceptions.DescriptorException.invalidIndirectionPolicyOperation(Descripto
    rException.java:669)
    at oracle.toplink.internal.indirection.ContainerIndirectionPolicy.buildContainer(ContainerIn
    directionPolicy.java:62)
    at oracle.toplink.internal.indirection.ContainerIndirectionPolicy.valueFromQuery(ContainerIn
    directionPolicy.java:254)
    at oracle.toplink.mappings.ForeignReferenceMapping.valueFromRow(ForeignReferenceMapping.java
    :898)
    at oracle.toplink.mappings.OneToOneMapping.valueFromRow(OneToOneMapping.java:1302)
    at oracle.toplink.mappings.DatabaseMapping.readFromRowIntoObject(DatabaseMapping.java:876)
    at oracle.toplink.internal.descriptors.ObjectBuilder.buildAttributesIntoObject(ObjectBuilder
    .java:164)
    at oracle.toplink.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:322)
    at oracle.toplink.queryframework.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:
    242)
    at oracle.toplink.queryframework.ReadObjectQuery.execute(ReadObjectQuery.java:368)
    at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:510)
    at oracle.toplink.queryframework.ReadQuery.execute(ReadQuery.java:125)
    at oracle.toplink.publicinterface.Session.internalExecuteQuery(Session.java:1962)
    at oracle.toplink.publicinterface.Session.executeQuery(Session.java:1086)
    at oracle.toplink.internal.indirection.NoIndirectionPolicy.valueFromQuery(NoIndirectionPolic
    y.java:254)
    at oracle.toplink.mappings.ForeignReferenceMapping.valueFromRow(ForeignReferenceMapping.java
    :898)
    at oracle.toplink.mappings.OneToOneMapping.valueFromRow(OneToOneMapping.java:1302)
    at oracle.toplink.mappings.DatabaseMapping.readFromRowIntoObject(DatabaseMapping.java:876)
    at oracle.toplink.internal.descriptors.ObjectBuilder.buildAttributesIntoObject(ObjectBuilder
    .java:164)
    at oracle.toplink.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:322)
    at oracle.toplink.queryframework.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:
    242)
    at oracle.toplink.queryframework.ReadObjectQuery.execute(ReadObjectQuery.java:368)

    Clients of your class might not like you throwing
    exceptions from the ctor. If they're checked
    exceptions it'll mean try/catch blocks. If there are
    LOTS of checked exceptions that'll mean lots of catch
    blocks. Could get messy fast. You could catch in the
    ctor and wrap in a subclass of
    java.lang.RuntimeException. Those are unchecked, like
    java.lang.IllegalArgumentException.I would strongly advise against making your checked exceptions unchecked just so that the caller's code will compile without try/catch blocks. Either way--checked or unchecked--if I do Foo foo = new Foo();
    foo.doStuff(); I won't get to doStuff() if the ctor threw an exception.
    You'd throw unchecked exceptions in those cases where it's appropriate--e.g., the caller passed you invalid args (bad code on the caller's part, appropriated for unchecked exception), or the VM couldn't get enough memory to create your object (probably not something the caller can do anything about, so, again, appropriate for unchecked).
    But if, for example, he's passing you database login parameters that an end user provided, and the password is wrong or the host is unreachable, then you'd want to throw a checked exception, because it's not bad code on the caller's part, and there might be something he can do to recover.
    Note that the example of the incorrect password above is quite different from the "invalid args" example in the previous paragraph. Your method would throw IllegalArgumentException if the caller passed args that violate your method's precondition--e..g. lie outside some range of numbers. That is, it's a value that your method simply can't use. A bad password for a db login, on the other hand, is legal as far as your method is concerned, it just failed authentication in the db.
    @%: I know you're aware of the proper use of checked/unchecked exceptions, but the way you worded you post kind of sounded like you were saying, "just use unchecked if you find the caller has too many try statements."
    &para;

  • How can I throw exceptions using JAX-WS 2.0?

    I have been using NetBeans5.5 to develop a web service from a WSDL i.e. I write the XSD and WSDL first then generate the web service code in NetBeans5.5. How can I throw an exception so that details of the exception will be contained within the SOAP xml response? For example:
    <soapenv:Body>
            <soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                   <faultcode>MyFaultCode</faultcode>
                   <faultstring>MyFaultString</faultstring>
            </soapenv:Fault>
    </soapenv:Body>In the above sample message FaultCode and FaultString would be something that I can specify, perhaps the contents of another caught exception. I really need to have some way to display meaningful data to anyone which consumes this web service and where an exception occurs.

    You can throw a javax.xml.ws.soap.SOAPFaultException. https://jax-ws.dev.java.net/nonav/jax-ws-20-fcs/api/javax/xml/ws/soap/SOAPFaultException.html

  • Can't throw exception inside try block!

    Hi,
    I'm having a problem trying to throw an error inside a try block.
    To illustrate:
    public class TestException {
    public TestException() {
    try {
    int ret = foo();
    System.out.println("ret is " + ret);
    } catch (Exception ex) {
    System.out.println("exception caught");
    public int foo() throws Exception {
    int ret = 0;
    try {
    throw new Exception("test exception");
    } finally {
    return ret;
    public static void main(String[] args) {
    new TestException();
    If I run this the only output is "ret is 0" - I do not catch the thrown exception! What am I doing wrong?
    Any and all help will be very gratefully received.
    Thanks.

    I need to correct myself: I've re-read the spec, and actually the behaviour is conformant with the JLS: JLS says that the return statement completes abruptly, and an abrupt return in a finally block that didn't have a (applicable or any) catch block will result in the original exception being 'forgotten'.
    Very unintuitive, but as-spec'ed

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

  • Throws Exception - a newcomer...

    I have written a small amount of code that takes information from a text file and displays it in a GUI (swing) - this is called my RasterDisplay class. However, I am now creating another part of the GUI which will have a button that makes a new RasterDisplay. However, when I try and call my RasterDisplay constructor from within my actionPerformed method (see below) It tells me I have an "unhandled Exception type Exception". I can't throw Exception in the actionPerformed method so how do I get this method to work? Any help would be greatly appreciated - I am a total newcomer to Java and can't make head nor tail of related topics in all the forums...
    Cheers!
    import javax.swing.*;
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    public class RasterToolbar extends JFrame implements ActionListener{
         JButton open;
         public static void main(String[] args) throws Exception{
              new RasterToolbar();
         //method to make display panel with buttons
         public RasterToolbar()throws Exception{
                   super("Raster Viewer 1.0 beta");
                   setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                   Container contentPane = getContentPane();
                   JPanel p1 = new JPanel();
                   p1.setLayout(new FlowLayout());
                   p1.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
                   open = new JButton("Open Viewer");
                   p1.add(open);
                   contentPane.add(p1,BorderLayout.WEST);
                   open.addActionListener(this);
                   pack();
                   setVisible(true);
         public void actionPerformed(ActionEvent ev){
         if(ev.getSource()== open){
              System.out.println("Open pressed");
              RasterDisplay viewer = new RasterDisplay(); // HERE IS THE PROBLEM LINE!
    }

    public void actionPerformed(ActionEvent ev){
         if(ev.getSource()== open){
              System.out.println("Open pressed");
              try {
                   RasterDisplay viewer = new RasterDisplay(); // HERE IS THE PROBLEM LINE!
              } catch(Exception e) {
                   // do what ever you want here!
                   e.printStackTrace();
    }

  • Constructor can throw exception or Not ?

    Anybody please tell me if the constructor throws an exception or not ?
    Please reply soon
    Thanks
    Amitindia

    A constructor can throw an Exception. However I
    would suggest throwing the generic Throwable, Error,
    Exception or RuntimeException rather than a specific
    exception is bad practice and you should choose an
    appropirate exception to throw.All depends on wich kind of exception you are throwing,checked or unchecked. It's an even worse form to throw a RE, Error, or Throwable when you are throwing in fact a checked exception.
    Nevertheless, I do agree, you must always strive to not throw exceptions, of any kind, in your construtor code. Construtors should be simple and reliable. Unles you have a very compelling reason to not do it, try to isolate the risky parts of the code where they are called ofter object construction or class loading.
    May the code be with you.

  • Throw difference exception in constructor

    Have a base class constructor that throws an exception of class XException
    Have an exception class YException that inherit exception XException
    If I inherit the base class, can I make it throw exception Y instead of X, since Y is a subclass of exception X?
    Example:
    public class Base {
    public Base() throws XException {
    public class XException extends Exception {
    public XException() {
    // etc...
    public YException extends XException {
    YException() {
    super();
    public MyClass extends Base {
    // Can this work in a constructor since YException is a subclass of XException?
    // Anyway to make this possible?
    public MyClass() throws YException {
    super();

    Have a base class constructor that throws an exception
    of class XException
    Have an exception class YException that inherit
    exception XException
    If I inherit the base class, can I make it throw
    exception Y instead of X, since Y is a subclass of
    exception X?
    Example:
    public class Base {
    public Base() throws XException {
    public class XException extends Exception {
    public XException() {
    // etc...
    public YException extends XException {
    YException() {
    super();
    public MyClass extends Base {
    // Can this work in a constructor since YException is
    a subclass of XException?
    // Anyway to make this possible?
    public MyClass() throws YException {
    super();
    Apart from what you are asking in normal circumstances a no args constructor throwing an exception is never a good idea. The reason being that from then on anybody who extends this class would have to face problems. Consider the following
    public class MyTest
          public MyTest() throws Exception
    class Test extends MyTest
    {}this would not compile and throw the following error
    Default constructor cannot handle exception type Exception thrown by implicit super constructor. Must define an explicit constructor     
    So thats not a good practice
    cheers

  • Throw different exception in constructor

    Have a base class constructor that throws an exception of class XException
    Have an exception class YException that inherit exception XException
    If I inherit the base class, can I make it throw exception Y instead of X, since Y is a subclass of exception X?
    Example:
    public class Base {
    public Base() throws XException {
    public class XException extends Exception {
    public XException() {
    // etc...
    public YException extends XException {
    YException() {
    super();
    public MyClass extends Base {
    // Can this work in a constructor since YException is a subclass of XException?
    // Anyway to make this possible?
    public MyClass() throws YException {
    super();

    An overriding method in a sub-class may throw a sub-class of the Exception thrown in the extended class.
    Constructors are not overridden, the super() may generate an exception of type XException, which the constructor in the sub-class does not specifiy.

  • 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 exception error everywhere in JSP!

    I've wrote a JSP to access SQL Server database in J2SE sucessfully, but when
    I try that on a different server using Java 1.1 I get the same type of
    errors complaining about
    "the method " blah blah blah" can throw the checked exception
    "java/lang/ClassNotFoundException", but its invocation is neither enclosed
    in a try statement that can catch that exception nor in the body of a method
    or constructor that "throws" that exception."
    this is another sample of my errors
    31. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    <------------------------------------------->
    *** Error: The method "java.lang.Class forName(java.lang.String $1);" can
    throw the checked exception "java/lang/ClassNotFoundException", but its
    invocation is neither enclosed in a try statement that can catch that
    exception nor in the body of a method or constructor that "throws" that
    exception.
    33. Connection con=DriverManager.getConnection(url, "ema", "ema");
    <-------------------------------------------->
    *** Error: The method "java.sql.Connection getConnection(java.lang.String
    $1, java.lang.String $2, java.lang.String $3);" can throw the checked
    exception "java/sql/SQLException", but its invocation is neither enclosed in
    a try statement that can catch that exception nor in the body of a method or
    constructor that "throws" that exception.
    Am I missing some libraries or calling the method incorrectly because of the
    version of Java was older?
    Here I also attached my code
    <%
    //connection and query
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url="jdbc:odbc:DB";
    Connection con=DriverManager.getConnection(url, "sa", "password");
    PreparedStatement query = con.prepareStatement("select Quarter, Month,
    WeekDay, statusCode, Responded, CNT from REQUEST",
    ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = query.executeQuery();
    rs.last();
    int numrows = rs.getRow();
    rs.beforeFirst();
    %>
    Thanks in advanced
    Ku

    I've wrote a JSP to access SQL Server database in J2SE sucessfully, but when
    I try that on a different server using Java 1.1 I get the same type of
    errors complaining about
    "the method " blah blah blah" can throw the checked exception
    "java/lang/ClassNotFoundException", but its invocation is neither enclosed
    in a try statement that can catch that exception nor in the body of a method
    or constructor that "throws" that exception."
    this is another sample of my errors
    31. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    <------------------------------------------->
    *** Error: The method "java.lang.Class forName(java.lang.String $1);" can
    throw the checked exception "java/lang/ClassNotFoundException", but its
    invocation is neither enclosed in a try statement that can catch that
    exception nor in the body of a method or constructor that "throws" that
    exception.
    33. Connection con=DriverManager.getConnection(url, "ema", "ema");
    <-------------------------------------------->
    *** Error: The method "java.sql.Connection getConnection(java.lang.String
    $1, java.lang.String $2, java.lang.String $3);" can throw the checked
    exception "java/sql/SQLException", but its invocation is neither enclosed in
    a try statement that can catch that exception nor in the body of a method or
    constructor that "throws" that exception.
    Am I missing some libraries or calling the method incorrectly because of the
    version of Java was older?
    Here I also attached my code
    <%
    //connection and query
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url="jdbc:odbc:DB";
    Connection con=DriverManager.getConnection(url, "sa", "password");
    PreparedStatement query = con.prepareStatement("select Quarter, Month,
    WeekDay, statusCode, Responded, CNT from REQUEST",
    ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = query.executeQuery();
    rs.last();
    int numrows = rs.getRow();
    rs.beforeFirst();
    %>
    Thanks in advanced
    Ku

  • How to handle exceptions in constructor?

    Hello everyone,
    When exceptions occur in constructor so that the instance of the object can not be created, should we throw the exception to the invoker of the constructor or simply catch the exception (and not throw it again)?
    I think we should not catch the exception (and not throw it again), since in this approach, the invoker can not see whether the instance of the object has been created successfully.
    I think we should throw the exception to let the invoker know that the instance of the object has not been created successfully, so that the invoker can peform appropriate actions. But I am not quite sure whether I am correct since I have not seen any constructors which throw exceptions before.
    Could anyone help?
    Thanks in advance,
    George

    Thanks tjacobs01,
    instance of the object can not be created, shouldwe
    throw the exception to the invoker of theconstructor
    or simply catch the exception (and not throw it
    again)?It really depends. If you are constructing an object
    and you hit an exception that you can't recover from
    internally, then yeah, I think you should throw an
    exception, since your object isn't going to work
    anyway.
    I think we should not catch the exception (and not
    throw it again), since in this approach, theinvoker
    can not see whether the instance of the object has
    been created successfully.Exactly
    whether I am correct since I have not seen any
    constructors which throw exceptions before.You probably have. How about java.net.URL? (BTW,
    MalformedURLException is the worst checked exception
    (ie not runtimeException) in Java. Can anyone explain
    how File.toURL() could EVER throw a
    MalformedURLException???Your reply is very helpful!
    regards,
    George

  • Function module JOB_CLOSE throwing exception

    Hello,
    We have a batch job which has 2 steps:
    1) Step 1 uses job_open, job_submit and job_close and immediately schedules batch job A/P_ACCOUNTS which in turn creates batch input sessions A/P_ACCOUNTS.
    2) Step 2 Processes A/P_ACCOUNTS sessions created yesterday or today.
    In few cases, job_close is throwing exception job_close_failed. I believe that error is coming due to non availability of work processes. Job A/P_Accounts is defined as a class C batch job. There is a check in the FM job_close which does the following check:
    - if the class of a batch job is B or C, it calculates the number of free work processes. If there are no work processes available then JOB_CLOSE throws JOB_CLOSE_FAILED exception. 
    - If the class is u2018Au2019, it skips this check.
    We have an option of changing the class of batch job to A but there are some system critical jobs that are running as class A.
    My question is:
    In the code, JOB_CLOSE has been called for scheduling the job A/P_ACCOUNTS with parameter start immediately. Can anyone please let me know what will happen if function JOB_CLOSE is not called with start immediately option? Will the batch job A/P_ACCOUNTS wait till the time work processes are available?
    Or, can anything else be done to solve the issue?
    Regards,
    Siddharth

    HI,
    This is my experience with job_close..
    when i was working in zprograms then i was able to scedule it any time i wanted..
    but in my standard program when i tried it didn't worked....
    so i have to use that option of starting it immediately..
    and then it is working fine..
    now if i schedule 5 jobs... one after another..
    its get queued up...and once the processor is free...its working..
    my code of job close
      CALL FUNCTION 'JOB_CLOSE'
        EXPORTING
          jobcount             = job_count
          jobname              = job_name
          strtimmed            = yes " yes = 'X'
        IMPORTING
          job_was_released     = job_released
        EXCEPTIONS
          cant_start_immediate = 1
          invalid_startdate    = 2
          jobname_missing      = 3
          job_close_failed     = 4
          job_nosteps          = 5
          job_notex            = 6
          lock_failed          = 7
          invalid_target       = 8
          OTHERS               = 9.
    regards,
    Yadesh

  • Using sql bulk copy throwing exception -The given value of type String from the data source cannot be converted to type int of the specified target column

    Hi All,
    I am reading notepads files and inserting data in sql tables from the notepad-
    while performing sql bulk copy on this line it throws exception - "bulkcopy.WriteToServer(dt); -"data type related(mentioned in subject )".
    Please go through my  logic and tell me what to change to avoid this error -
    public void Main()
    Dts.TaskResult = (int)ScriptResults.Success;
    string[] filePaths = Directory.GetFiles(@"C:\Users\jainruc\Desktop\Sudhanshu\master_db\Archive\test\content_insert\");
    for (int k = 0; k < filePaths.Length; k++)
    string[] lines = System.IO.File.ReadAllLines(filePaths[k]);
    //table name needs to extract after = sign
    string[] pathArr = filePaths[0].Split('\\');
    string tablename = pathArr[9].Split('.')[0];
    DataTable dt = new DataTable(tablename);
    |
    string[] arrColumns = lines[1].Split(new char[] { '|' });
    foreach (string col in arrColumns)
    dt.Columns.Add(col);
    for (int i = 2; i < lines.Length; i++)
    string[] columnsvals = lines[i].Split(new char[] { '|' });
    DataRow dr = dt.NewRow();
    for (int j = 0; j < columnsvals.Length; j++)
    //Console.Write(columnsvals[j]);
    if (string.IsNullOrEmpty(columnsvals[j]))
    dr[j] = DBNull.Value;
    else
    dr[j] = columnsvals[j];
    dt.Rows.Add(dr);
    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = "Data Source=UI3DATS009X;" + "Initial Catalog=BHI_CSP_DB;" + "User Id=sa;" + "Password=3pp$erv1ce$4";
    conn.Open();
    SqlBulkCopy bulkcopy = new SqlBulkCopy(conn);
    bulkcopy.DestinationTableName = dt.TableName;
    bulkcopy.WriteToServer(dt);
    conn.Close();
    Issue 1:-
    I am reading notepad: getting all column and values in my data table now while inserting for date and time or integer field i need to do explicit conversion how to write for specific column before bulkcopy.WriteToServer(dt);
    Issue 2:- Notepad does not contains all columns nor in specific sequence in that case i can add few column ehich i am doing now but the issue is now data table will add my columns + notepad columns and while inserting how to assign in perticular colums?
    sudhanshu sharma Do good and cast it into river :)

    Hi,
    I think you'll have to do an explicit column mapping if they are not in exact sequence in both source and destination.
    Have a look at this link:
    https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopycolumnmapping(v=vs.110).aspx
    Good Luck!
    Kaur.
    Please mark as answer if this resolves your issue.

  • How to throw exception in run() method of Runnable?

    Hi, everyone:
    I want to know how to throw exception in run() method of interface Runnable. Since there is no throwable exception declared in run() method of interface Runnable in Java API specification.
    Thanks in advance,
    George

    Thanks, jfbriere.
    I must add though that if your run() methodis
    executed after a call to Thread.start(), then
    it is not a good choice to throw anyRuntimeException
    from the run() method.
    The reason is that the thrown exception won't be
    handled appropriately by a try-catch block.Why do you say that "the thrown exception won't be
    handled appropriately by a try-catch block"? Can you
    explain it in more detail?
    regards,
    George
    Because the other thread runs concurrently with and independently of the parent thread, there's no way you can write a try/catch that will handle the new thread's exception: try {
        myThread.start();
    catch (TheExceptionYouWantToThrowFromRun exc) {
        handle it
    do the next thing This won't work because the parent thread just continues on after myThread.start(). Start() doesn't throw the exception--run() does. And our parent thread here has lost touch with the child thread--it just moves on to "do the next thing."
    Now, you can do some exception handling with ThreadGroup and uncaughtException(), but make sure you understand why the above won't work, in case that was what you were planning to do.

Maybe you are looking for

  • How do I get rid of "do you want to allow the following program to make changes to this computer"?

    I recently installed Adobe Acrobat 8 Professional and every time I open a PDF file that is stored on my computer, I get a pop-up that asks "Do you want to allow the following program to make changes to this computer?".  How do I get rid of this?  I d

  • Adding custom fields to standard table control in IW51

    Hi, I have added 4 custom fields to the standard table QMEL through the structure CI_QMEL . In transaction IW51 there is a table control as show in the screenshot below. The 4 custom fields which i have added in the standard table should also be adde

  • Sys_context - Error in Oracle 8 Database

    I am using sys_context but it gives error message. SELECT SYS_CONTEXT ('userenv', 'host') FROM dual ------ it gives following message SELECT SYS_CONTEXT ('userenv', 'host') FROM dual ERROR at line 1: ORA-00904: invalid column name Pl. help me urgentl

  • Stop motion animation help using images from a digital camera...how tricky is this?

    I'm teaching a media arts course for the first time, and I'm trying to figure out how to use images taken with a digital camera, import them to Premiere Elements 7, and put them in the timeline without having to shorten the length of them.  As soon a

  • Insufficient privileges in Foreing Key

    I created a table in user2 schema (Oracle 8.1.5) Create table test (company number(2)); Then i try to add a foreing key ALTER TABLE test ADD ( FOREIGN KEY (company) REFERENCES otheruser.COMPANY); I always get the ORA-01031 error (insufficient privile