Using an unchecked exception to alter flow control inside a class

Best-practice question:
Is it wrong to use an unchecked exception in an if-like manner?
For example, instead of using:
if (condition) {
-----------a lot of code-----------------
} else {
----------some more code--------------
Is it wrong to do it like this?
try {
if (!condition) throw new IllegalArgumentException();
-------------a lot of code---------------
} catch (IllegalArgumentException e) {
--------------some more code-----------
I'm asking because I used this kind of practice recently in a piece of code i wrote (actually i used it to validate an argument I received from a html-form and post an error message in the catch block) and a colleague told me it was bad practice.
If it IS bad practice, when should you actually use unchecked exceptions like IllegalArgumentException?
I already posted this question in the newbie forum, but didn't get any answers. Anybody here can explain this to me please?

It is fine to use IllegalArgumentException, but typically it is used when the code generating the exception and the client who is using the code that generates the exception are two different pieces of code.
If you were writing some kind of library for others to use. It would make sense to throw this exception out of your library if the user gave you wrong data.
But you shouldn't use exceptions as normal program logic.

Similar Messages

  • Checked and unchecked exceptions - when to use which ?

    Hi,
    Example:
    public void go(String[] args) {
       if(args.length==0)
          throw new //   <= what type of an exception should come here ?
    }Is there a good explanation when to use which one ? I know that generally
    unchecked exception are the exceptions associated with errors in the logic
    of your applications and checked are those which you can not determine
    (like files, networks problems ....).
    Thanks,
    Adrian

    There is no, "I think it is better to us a type-XXX exception here because of conditions 1, 2, and 3" scenario.
    Checked exceptions are of type java.lang.Exception and must be handled in one of two ways- try/catch constructs or having the method state it throws the checked exception.
    Unchecked exceptions are of type java.lang.Error or java.lang.RuntimeException. If the problem is an Error, something very bad has occurred like running out of memory. If it is a RuntimeError, then it probably came from a program bug. In both cases, there is no way for you to know when they will arise. Therefore the compiler does not force you to handle these unusual circumstances.
    If you think of piece of code may throw an error like an I/O operation, and you do not have code to handle that possibility, the compiler will let you know. After you have been programming long enough, you'll begin to know when you need try/catch constructs without Mr. Compiler yelling at you. ;-)
    Edited by: filestream on Sep 14, 2007 5:37 PM

  • Problems with parity and flow control using visa serial

    I am trying to create a basic user interface with the options that my
    company uses most often for a force indicator.  You can configure
    the indicator over serial, as well as read the values off the
    indicator.  I am trying to create the user interface so that using
    producer/consumer loops with events, once you change a value, it will
    write that new value to the serial port, ie the device. 
    The problem I am having is transfering the parity and flow control
    values for the serial config to the Basic read write VI.  The
    problem is that once the consumer loop executes, it will write the
    values correctly to the VI, but then the outer loop executes 200 ms
    later and clears the values.  I know that this is normal behavior
    and that in order to keep the values stored, normally you would use a
    shift register.  I tried to use this and had some issues with
    correct data types/array mis-mtaches, ets, so I created an indicator
    and had a local vaible read the indicator, which seems to be working
    for the stop bits, read bits, baud rate, etc, but not the parity anf
    flow control.  I always get "blank" outputs for theses values (if
    you enable the digital display you can see that they are outputing the
    value 0 which correspondes to None in both cases, which is
    correct).  Even though it appears that it is outputting the
    correct value, I get an error that says the VISA property is
    invalid.  I initally did a search and found that my stop bit
    control was wrong (outputting double instead of integer), but I could
    not find anything on the parity/flow control issue.  I even tried
    to copy the serial config controls from the basic serial read/write to
    my dialog box and that did not work either.
    I would be grateful for any suggestions.
    Thanks
    Kenny
    Kenny
    Attachments:
    BGI_main pandc.zip ‏232 KB

    I should add that I am using LV 8.0 and that the serial config
    indicator in the consumer loop will be off the frontpanel in the final
    VI so that it is not visible to the user.
    Kenny

  • Standard flow control

    JSTL support for standard flow control.
    what that means ?
    I am aware of that JSTL can help in SQL processing , XML processing through Tag libraries.
    But however, how the JSTL supports standard flow control ? is it the JSTL iterator we are talking about ?

    Although you can apparently access a database on the JSP page using JSTL tags, it doesn't mean its a good idea. I suggest you use the MVC design. You separate the layers and not put database functionality in the presentation layer (JSP).
    Hers is one MVC approach in which a single servlet acts as the control. There are other ways of doing it via Spring, Structs, etc. However, I suggest you master this approach before moving onto those.
    presentation layer:
    JSP, CSS, Javascript, and JSTL.
    The JSP page and its supporting languages is responsible for displaying data and submitting user input back the controller. The Javascript is typically responsible for basic client side validation of user input. JSP gets its data that it is to display from request scope (and perhaps some from session scope). JSTL assists JSP in displaying data by doing such tasks as looping though a Java collection from the request scope and displaying it. The JSP page should not contain any logic from the other layers (below). The page will get complicated enough over time just displaying data without making it even more difficult to read by inserting business logic into it.
    control layer:
    A single servlet. This servlet takes in all url request and page submits coming from JSP pages. Avoid JSP to JSP page naviigation (there are exceptions to this rule). Go through the control layer. This servlet calls business logic to get data that the page requests. It puts it in request and/or session scope, and dispatches to the appropriate JSP page. Because all url request go through this servlet, the servlet can do centralized authentication (log in) and authorization (user assigned to a role). Dont generate presentation data (html) from this layer.
    business layer:
    Java classes that carry out requests from the control layer. It calls the database layer for raw data from the database and performs business logic on the data (if any) before sending it to the control layer.
    database layer:
    Takes in requests from the business layer. Queries the database via SQL. Is the only layer that has sql in it. Reads the resultSet from the database and puts the data in some kind of Java collection before returning it to the business layer. Never return the resultSet (a database concept) to the business layer.

  • Paused for Flow Control but no flow occurring

    10.2.0.2
    Our destination database had problems this AM and it was bounced. The capture process on the source went into "Paused for Flow Control" status and never recovered. Here's the process I went through.
    1. There was nothing being propagated according to v$propagation_sender.
    2. The apply process was running but was not receiving any messages according to v$streams_apply_reader, v$streams_apply_server
    3. I stopped and restarted the apply process - no change.
    4. I stopped and restarted the capture process and after the dictionary initilization it went back into the paused state.
    5. alter logs showed nothing for either database.
    6. dbms_propagation_adm.stop_propagation resulted in an ORA-24082
    I finally had to run dbms_propagation_adm.stop_propagation with force=>true and restart it for data to start flowing again, albeit slowly.
    So the question is - why? Why did I have to forcefully stop the propagation process and restart it when this is all supposed to be seamless? Is this expected behavior that others have run into and the proces you need to perform whenever your destination becomes unavailable for a time period?
    Just curious.
    Thanks - Brian

    I've tried setting up a Streams for schema replication and have run into the "Paused for Flow Control issue". I'm not getting any streams errors so i don't know what's wrong with it.
    I'm not that familiar with Streams so i'm not sure where to start to diagnose the problem. I used the Enterprise Manager to set up the streams and tried stopping and restarting the capture process but i'm still getting the "Paused for Flow Control issue". Where is the best place to start to look for a solution?
    Thanks!

  • Message Flow Control

    Hello,
              as I read, WLS provides the possibility to slow down message producers when certain paging thresholds are exceeded. I'm not quite sure, if the slow down of a producer is tied to it's session lifecycle, i.e. if the producer is slowed down only within its current session - or are producers, which are created from a new session, also slowed down right from the start.
              It would be great if someone could answer that. Unfortunately I have found nothing about that in the documentation.
              Regards,
              Dirk

    Hello Tom.
              First of all, thank you for your quick response. This forum is really working!
              I searched for this topic in the documentation, but didn't find anything appropriate explaining the in-depth details of the JMS flow control mechanism. Therefore, I wrote a simple test case (implementation and server configuration is attached at the end of this message) to check the flow control handling for certain conditions. Since there is no API to access the flow control properties of a message producer, I measured the JMS throughput within the test case and tried to derive some conclusions.
              Regarding the server configuration:
              - I configured one JMS Server (Test_JMSServer) with one Queue (TestQueue). I enabled the message paging at server level, starting at 1000 messages (i.e. message threshold high). The lower message threshold was set to 100 messages. As a paging store a file store (TestPagingStore) was used.
              - Message thresholds at destination level was disabled.
              - I further configured a connection factory (TestConnectionFactory) for which I enabled the flow control with a max. throughput of 50 msg/sec and a min. throughput of 1 msg/sec. The flow interval was set to 60 seconds, the number of steps was set to 6.
              Regarding the test case:
              There are 3 scenarios within the test case. Within each scenario
              - first all messages are consumed from the queue,
              - then 1000 messages are send to the queue in a row, thereby measuring the throughput,
              - finally again 1000 messages are send to the queue in a row, thereby measuring the throughput.
              The scenarios differ in how the bulk-send operation is performed.
              - The first scenario (test_noReuse) creates a new connection for each message to be send.
              - The second scenario (test_sessionReuse) creates a new session at the start and reuses that session for sending the messages. A new sender is created of each message.
              - The third scenario (test_senderReuse) creates a new sender at the start and reuses that sender for sending the messages.
              Here are the results of the test:
              ==[test_noReuse]=======================
              Cleaned up <2000> messages.
              Throughput (messages/second): 51 [startMillis=1161249409788;endMillis=1161249429210;messagesSend=1000]
              Throughput (messages/second): 62 [startMillis=1161249429210;endMillis=1161249445304;messagesSend=1000]
              ==[test_sessionReuse]=======================
              Cleaned up <2000> messages.
              Throughput (messages/second): 231 [startMillis=1161249452773;endMillis=1161249457101;messagesSend=1000]
              Throughput (messages/second): 245 [startMillis=1161249457101;endMillis=1161249461179;messagesSend=1000]
              ==[test_senderReuse]=======================
              Cleaned up <2000> messages.
              Throughput (messages/second): 790 [startMillis=1161249467351;endMillis=1161249468616;messagesSend=1000]
              Throughput (messages/second): 1 [startMillis=1161249468616;endMillis=1161249999226;messagesSend=1000]
              To me it seems, that reusing a session has no effect on the message flow control if a new sender is created for sending a message. The only scenario where a throttling occurs (at least it seems to be that way) is the last scenario, where the sender is reused for all messages.
              So my conclusion is, that message control flow is superfluous to configure, as long as
              - you don't have a small amount of (batch) message producers, each of which reusing a single sender for each message,
              - or you have some cache of senders (or a single sender) in your application and reuse the cached senders for sending messages.
              The latter is, of course, strongly discouraged, since neither JMS sessions, nor senders are thread-safe. So you need to implement some thread-safe cache and also have to deal with re-creating stalled JMS resources within that cache -- a really non-trivial implementation. Further, if many different threads produce messages, the flow control has no (or at least few) effect on the message load in the server.
              I just ask myself, what the flow control was designed for, since the cases where it really applies are rather rare, IMHO. Or have I made some error in the test or in the server configuration?
              Best regards,
              Dirk
              The test class:
              <pre>
              import java.util.Hashtable;
              import javax.jms.BytesMessage;
              import javax.jms.JMSException;
              import javax.jms.Message;
              import javax.jms.Queue;
              import javax.jms.QueueConnection;
              import javax.jms.QueueConnectionFactory;
              import javax.jms.QueueReceiver;
              import javax.jms.QueueSender;
              import javax.jms.QueueSession;
              import javax.jms.Session;
              import javax.naming.InitialContext;
              import junit.framework.TestCase;
              public class JMSFlowControlTest extends TestCase {
              private int messagesThresholdHigh = 1000;
              private QueueConnectionFactory conFactory;
              private Queue queue = null;
              protected void setUp() throws Exception {
              super.setUp();
              InitialContext ctx = null;
              Hashtable ctxEnv = null;
              ctxEnv = new Hashtable();
              ctxEnv.put(
              InitialContext.INITIAL_CONTEXT_FACTORY,
              "weblogic.jndi.WLInitialContextFactory");
              ctxEnv.put(
              InitialContext.PROVIDER_URL,
              "t3://localhost:7001");
              ctx = new InitialContext(ctxEnv);
              this.queue = (Queue) ctx.lookup("jms/queue/TestQueue");
              this.conFactory = (QueueConnectionFactory)
              ctx.lookup("jms/factory/TestConnectionFactory");
              public void test_noReuse() throws Exception {
              System.out.println();
              System.out.println("==[" + this.getName() + "]=======================");
              this.cleanupQueue();
              System.out.println(
              this.bulkSendMessage(
              this.messagesThresholdHigh,
              1024));
              System.out.println(
              this.bulkSendMessage(
              this.messagesThresholdHigh,
              1024));
              public void test_sessionReuse() throws Exception {
              QueueConnection con = null;
              QueueSession session = null;
              System.out.println();
              System.out.println("==[" + this.getName() + "]=======================");
              try {
              con = this.conFactory.createQueueConnection();
              session =
              con.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
              this.cleanupQueue();
              System.out.println(
              this.bulkSendMessage(
              session,
              this.messagesThresholdHigh,
              1024));
              System.out.println(
              this.bulkSendMessage(
              session,
              this.messagesThresholdHigh,
              1024));
              } finally {
              if (con != null) {
              try {
              con.close();
              } catch (JMSException e) {}
              public void test_senderReuse() throws Exception {
              QueueConnection con = null;
              QueueSession session = null;
              QueueSender sender = null;
              System.out.println();
              System.out.println("==[" + this.getName() + "]=======================");
              try {
              con = this.conFactory.createQueueConnection();
              session =
              con.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
              sender = session.createSender(this.queue);
              this.cleanupQueue();
              System.out.println(
              this.bulkSendMessage(
              session,
              sender,
              this.messagesThresholdHigh,
              1024));
              System.out.println(
              this.bulkSendMessage(
              session,
              sender,
              this.messagesThresholdHigh,
              1024));
              } finally {
              if (con != null) {
              try {
              con.close();
              } catch (JMSException e) {}
              private Throughput
              bulkSendMessage(
              int messagesToSend,
              int messageSizeBytes)
              throws Exception {
              int messagesSend = 0;
              long startMillis = 0L;
              long endMillis = 0L;
              QueueConnection con = null;
              QueueSession session = null;
              QueueSender sender = null;
              startMillis = System.currentTimeMillis();
              for (int i = 0; i < messagesToSend; i++) {
              try {
              con = this.conFactory.createQueueConnection();
              session =
              con.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
              sender = session.createSender(this.queue);
              sender.send(this.createMessage(session, messageSizeBytes));
              messagesSend++;
              } finally {
              if (con != null) {
              try {
              con.close();
              } catch (JMSException e) {}
              endMillis = System.currentTimeMillis();
              return new Throughput(startMillis, endMillis, messagesSend);
              private Throughput
              bulkSendMessage(
              QueueSession session,
              int messagesToSend,
              int messageSizeBytes)
              throws Exception {
              int messagesSend = 0;
              long startMillis = 0L;
              long endMillis = 0L;
              QueueSender sender = null;
              startMillis = System.currentTimeMillis();
              for (int i = 0; i < messagesToSend; i++) {
              sender = session.createSender(this.queue);
              sender.send(this.createMessage(session, messageSizeBytes));
              messagesSend++;
              endMillis = System.currentTimeMillis();
              return new Throughput(startMillis, endMillis, messagesSend);
              private Throughput
              bulkSendMessage(
              QueueSession session,
              QueueSender sender,
              int messagesToSend,
              int messageSizeBytes)
              throws Exception {
              int messagesSend = 0;
              long startMillis = 0L;
              long endMillis = 0L;
              startMillis = System.currentTimeMillis();
              for (int i = 0; i < messagesToSend; i++) {
              sender.send(this.createMessage(session, messageSizeBytes));
              messagesSend++;
              endMillis = System.currentTimeMillis();
              return new Throughput(startMillis, endMillis, messagesSend);
              private Message
              createMessage(
              Session session,
              int messageSizeBytes)
              throws Exception {
              BytesMessage message = null;
              message = session.createBytesMessage();
              message.writeBytes(new byte[messageSizeBytes]);
              return message;
              private void cleanupQueue() throws Exception {
              QueueConnection con = null;
              QueueSession session = null;
              QueueReceiver receiver = null;
              Message message = null;
              int messageCount = 0;
              try {
              con = this.conFactory.createQueueConnection();
              session =
              con.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
              receiver = session.createReceiver(this.queue);
              con.start();
              do {
              message = null;
              message = receiver.receiveNoWait();
              if (message != null) {
              messageCount++;
              } while (message != null);
              } finally {
              if (con != null) {
              try {
              con.close();
              } catch (JMSException e) {}
              System.out.println("Cleaned up <" + messageCount + "> messages.");
              private static final class Throughput {
              private final long startMillis;
              private final long endMillis;
              private final int messagesSend;
              public Throughput(long startMillis, long endMillis, int messagesSend) {
              this.startMillis = startMillis;
              this.endMillis = endMillis;
              this.messagesSend = messagesSend;
              public int value() {
              long timeElapsedMillis = 0L;
              int timeElapsedSeconds = 0;
              int value = 0;
              timeElapsedMillis = this.endMillis - this.startMillis;
              if (timeElapsedMillis == 0) {
              timeElapsedMillis = 1;
              value = (int) ((this.messagesSend * 1000L) / timeElapsedMillis);
              return value;
              public String toString() {
              StringBuffer buffer = new StringBuffer();
              buffer
              .append("Throughput (messages/second): ").append(this.value())
              .append(" [startMillis=").append(this.startMillis)
              .append(";endMillis=").append(this.endMillis)
              .append(";messagesSend=").append(this.messagesSend)
              .append("]");
              return buffer.toString();
              </pre>
              The (partial) server configuration:
              <pre>
              <JMSConnectionFactory
              DefaultDeliveryMode="Non-Persistent"
              FlowMaximum="50"
              FlowMinimum="1"
              FlowSteps="6"
              JNDIName="jms/factory/TestConnectionFactory"
              Name="TestConnection Factory"
              Targets="SchufaDev"
              XAConnectionFactoryEnabled="true"/>
              <JMSFileStore Directory="filestore/paging" Name="TestPagingStore"/>
              <JMSServer
              MessagesPagingEnabled="true"
              MessagesThresholdHigh="1000"
              MessagesThresholdLow="100"
              Name="Test_JMSServer"
              PagingStore="TestPagingStore"
              Targets="SchufaDev">
              <JMSQueue
              CreationTime="1151395702234"
              JNDIName="jms/queue/TestQueue"
              JNDINameReplicated="false"
              Name="TestQueue"
              RedeliveryDelayOverride="5000"
              RedeliveryLimit="5"
              StoreEnabled="false"/>
              </JMSServer>
              </pre>

  • WL 8.1 - JMS Flow Control: How does it work

    I have been reading the documenattion on the way weblogic has its Flow
              Control setup. However I still have a few doubts. It would be great
              if some one can help.
              Background: I have a J2EE application deployed on the weblogic server
              (8.1 sp5) which connects as a Consumer to a Topic. On the other side I
              have a plain java application that acts as a producer and sends lots
              of small messages (about 300 bytes) out to the topic using
              MessageProducer.send() method.
              I would like to restrict the flow from this producer so that it waits
              if the consumers are unable to collect all messages from the topic.
              When I enable flow control, I can see log entries in my weblogic
              application that shows that it has beocme armed but it clears off the
              same second. However, I don't see any exceptions being raised at the
              producer side. How can I ensure that the producer is waiting x ms to
              send further messages across. I can't see anything at the producer
              side that would lead me to believe that the flow control is working. I
              also checked the properties for each of teh Session, Connection and
              COnnectionFactory attributes but could not come across any way where I
              could see that the producer knows about the quotas being implemented
              on the queue.
              Can someone throw some light?
              Thanks
              Vikash

    Hi,
              Except for the threshold log messages you mention, flow control is silent: no exceptions are thrown when a producer is flow controlled. Flow control simply slows down "send()" calls. You can control how long a flow controlled send() call will take via the connection factory settings. I suppose you can instrument your code to time the send() calls.
              Your statement "When I enable flow control, I can see log entries in my weblogic application that shows that it has beocme armed but it clears off the same second." is likely an indicator that flow control is working. You need to configure your thresholds to be farther apart if you want the flow control condition to last longer, and if you want to reduce the number of transitions in and out of flow-control.
              Tom
              P.S. The threshold settings in 8.1 also control paging. If you upgrade to a new version, then the threshold settings will only control flow-control. You will also likely get much much higher messaging performance - which can reduce the need for flow control.

  • Can I use my Time Capsule for wifi parental control?

    Can I use my Time Capsule for WiFi parental control.  The objective first is to use a time clock to control internet access (completely on or off).  Second objective is to use the Time Capsule which is also the WiFi router for more selective internet control?  Anyone out there have any tips on making this work?  We have Time Warner cable feeding the house internet, which is then corrected to the 2Tb Time Capsule which also provides our WiFi.  Any information including other alternatives would be most appreciated.  Surely we are not the only parents on the planet with this issue.  Thanks very much!

    how do I get the Mac addresses for each device (this won't be a problem, I demand the device, check it, and then return it).
    What wireless devices are we looking at here?
    Most devices have the AirPort ID or MAC Address or Hardware Address printed on the back or bottom of the device
    Otherwise, you can learn the correct number by process of elimination. Turn off all wireless devices except your Mac computer....if it is connecting using wireless.
    Open Macintosh HD > Applications > Utilities > AirPort Utility
    Click on the Time Capsule icon
    Look for Wireless Clients and click on the numerical IP address that is displayed
    Another box will open
    Look for the Hardware Address. It will be displayed as xx : xx : xx : xx :xx : xx
    Write that down and note that it is your Mac.
    Now, connect another wireless device and repeat the sequence.  Click on the "other" listing that you see to find out more info about that device.  Write down the ID or Address and note what device it is. Then power it off.
    Do the same for each wireless device that you want to have limited access.
    Post back when you have all the info.

  • Console flow control

    With no flow control on the console port, it's common to overrun the port when sending large config files from a terminal emulator. Is there any way to avoid this, other than manually breaking up the file and sending a chunk at a time, maybe by adjusting the console buffer size, if possible?

    Michael
    Most terminal emulator programs (like Hyperterm, or TeraTerm, or SecurCRT, etc) have a setting where you can specify character delay and or line delay. If you use these parameters to specify some delay you can send the config file (even very large configs) without over-running the console.
    HTH
    Rick

  • Want to know what exactly is flow control in odi

    Hi Experts
    I want to know what exactly is flow control in odi.can anybody explain with an example.i have created a simple interface ie using contol append km .in this both the tables are in one data server ie in different schemas.in this interface i have set the flow control as false.in what circumstances we will use this flow control.
    Regards
    sree

    Hi Sree,
    Couple of points u need to aware.
    There are two ways of Constraint checking in ODI (PK, FK, Condition, NOT NULL etc) using CKM.
    FLOW_CONTROL: If u enable this in ur IKM all the constraints checking will be done at I$ table (before target table loading).
    STATIC_CONTROL: If u enable this in ur IKM all the constraints checking will be done at TARGET table (after target table loading). In this case u need to DISABLE the constraint first and once STATIC_CONTROL is done then u need to ENABLE it.
    So all the violated/errored record will be moved to E$ table in both approach.
    Makes sense?
    Thanks,
    Guru

  • How to implement autotuning pid in labview in flow control process????

    I tried the same way as Example available in LabVIEW..... that is general auto PID simulator... But that didn't worked out for me.....

    The 'General Auto PID Simulator.vi' example uses the technique "PID Relay" feedback where it tries to calculate the PID values based on the relay feedback, but using the PID also in the loop:
    (http://zone.ni.com/reference/en-XX/help/370401H-01/lvpidmain/pidrelay_alg/)
    This technique works, but it requires initial PID parameters that will make the relay setpoint stable and it is able to obtain the results you are expecting.
    Now, for flow control, you can try the most classic techniques. Please use other shipping examples that start with "autotuning" and in special this:
    C:\Program Files (x86)\National Instruments\LabVIEW 2013\examples\control\PID\Autotuning PID Online.vi
    In this VI, you can choose other techniques like open-loop step response, closed-loop step response and the original 'relay feedback' where it doesn't have a PID inside the estimation loop.
    Anyway, here you have more information about those techniques http://zone.ni.com/reference/en-XX/help/370401H-01/TOC4.htm.
    One more thing: keep in mind that depending on the plant parameters, a PID could not be suited for your application and a more complex controller need to be developed.
    Hope this can help you...
    Barp - Control and Simulation Group - LabVIEW R&D - National Instruments

  • Why use customized / particular exceptions instead java.lang.Exception

    Hi,
    Do any of you guys know where can I find a theorical statement / explanation about why use particular / customized exceptions instead java.lang.Exception? I am aware that it consumes more resources and becomes a heavier object, as well as the clearness when coding and all that stuff; however, my boss wants to see a tech document where all this is clearly stated. Any resource over there?
    Regards

    It is better to throw specific--or at least module- or
    package-specific--excpetions, rather than Exception,
    because then the caller knows what to expect. However,
    if you declare "throws Exception", the caller can
    still catch IOException, SQLException, etc.,
    separately. He'll just have to be a really good
    guesser as to which ones he should catch.True.
    Also, there's no point in declaring "throws
    NullPointerException." Any method can throw it without
    declaring it. If you generate your own NPE (or other
    unchecked exception) inside the method, then you
    should document it in the javadoc comments, but you
    don't need to put it in the throws clause. It doesn't
    do any harm, but it's redundant and cluttersome.It was an example and I wasn't feeling too creative....excuse me. ;-) But yeah, I've never thrown NPE ever.
    I'm assuming overhead caused by extending classes.At
    the worst, it would be miniscule, or so I wouldthink.
    What overhead is created by extending classes?Hmm, I was under the impression that a class the extended another class, inherited all of the other classes data (variables, etc.). Hence, you get something like this:
    SuperClass1 + SubClass1 + SubClassOfSubcCass1 = Memory usuage for SubClassOfSubClass1.
    Since adding postivie number will always end up increasing data, SubClassOfSubClass1 will use more dtat than SuperClass1.
    Am I wrong?

  • ORA-25307: Enqueue rate too high, flow control enabled

    I am stuck. I have my stream setup and they were previously working on two of my dev environments well. Now when I get the streams setup the CAPTURE process has a state of "CAPTURING CHANGES" for like 10 seconds and then changes to state "PAUSED FOR FLOW CONTROL". I believe this is happening because the PROPAGATION process is showing an error of "ORA-25307: Enqueue rate too high, flow control enabled".
    I don't know what to tweak to get rid of this error message. The two environments are dev databases and there is minimal activity on them so i don't think it's a case of the APPLY process is lagging behind the PROPAGATION process. Has anyone run into this issue?? I've verified my db link works, my stream admin user has dba access. Any help or advise would be greatly appreciated.
    thanks, dave

    As rule of thumb, you don't need to set GLOBAL_NAME=TRUE as long as your are 100% GLOBAL_NAME compliant.
    So, setting GLOBAL_NAME=TRUE will not have any effect if your dblink is not global_name compliant
    and if your installation is global_name compliant, you don't need to set GLOBAL_NAME=TRUE.
    The first thing when you diagnose is to get the exact facts.
    Please run this queries both on source and target so that to see what are in the queues and where.
    Run it multiple time to see if figures evolves.
    - If they are fixed, then your Streams is stuck in its last stage. As a cheap and good starting point, just stop/start the capture, propagation and target apply process. Check also the alert.log on both site. when you have a propagation problem, they do contains information's. If you have re-bounced everything and no improvement then the real diagnose work must start here but then we know that the message is wrong and the problems is elsewhere.
    - if they are not fixed then your apply really lag behind for what ever good reason, but this is usually easy to find.
    set termout off
    col version new_value version noprint
    col queue_table format A26 head 'Queue Table'
    col queue_name format A32 head 'Queue Name'
    select substr(version,1,instr(version,'.',1)-1) version from v$instance;
    col mysql new_value mysql noprint
    col primary_instance format 9999 head 'Prim|inst'
    col secondary_instance format 9999 head 'Sec|inst'
    col owner_instance format 99 head 'Own|inst'
    COLUMN MEM_MSG HEADING 'Messages|in Memory' FORMAT 99999999
    COLUMN SPILL_MSGS HEADING 'Messages|Spilled' FORMAT 99999999
    COLUMN NUM_MSGS HEADING 'Total Messages|in Buffered Queue' FORMAT 99999999
    set linesize 150
    select case
      when &version=9 then ' distinct a.QID, a.owner||''.''||a.name nam, a.queue_table,
                  decode(a.queue_type,''NORMAL_QUEUE'',''NORMAL'', ''EXCEPTION_QUEUE'',''EXCEPTION'',a.queue_type) qt,
                  trim(a.enqueue_enabled) enq, trim(a.dequeue_enabled) deq, x.bufqm_nmsg msg, b.recipients
                  from dba_queues a , sys.v_$bufqm x, dba_queue_tables b
            where
                   a.qid = x.bufqm_qid (+) and a.owner not like ''SYS%''
               and a.queue_table = b.queue_table (+)
               and a.name not like ''%_E'' '
       when &version=10 then ' a.owner||''.''|| a.name nam, a.queue_table,
                  decode(a.queue_type,''NORMAL_QUEUE'',''NORMAL'', ''EXCEPTION_QUEUE'',''EXCEPTION'',a.queue_type) qt,
                  trim(a.enqueue_enabled) enq, trim(a.dequeue_enabled) deq, (NUM_MSGS - SPILL_MSGS) MEM_MSG, spill_msgs, x.num_msgs msg,
                  x.INST_ID owner_instance
                  from dba_queues a , sys.gv_$buffered_queues x
            where
                   a.qid = x.queue_id (+) and a.owner not in ( ''SYS'',''SYSTEM'',''WMSYS'')  order by a.owner ,qt desc'
       end mysql
    from dual
    set termout on
    select &mysql
    /B. Polarski

  • Find all unchecked exceptions thrown by method?

    Dear all,
    I am writing critical code that must be correct. Thus, I wish to know that I have not overlooked any important unchecked exceptions. I am aware that the distinction between unchecked and checked exceptions is controversial, and I know the difference between these types of exceptions.
    I would like to see for each function a list of all possible exceptions a method can throw. Preferably I would like a tool to do this for me, but I would write something myself if there is a reasonably simple way to do it.
    More precisely, I would like to be able to define the set of "unchecked" exceptions myself, e.g., I would put down NullPointerException as "unchecked", but I would let IOException be checked (in my particular application, not in general). In general, this would however be a very nice language feature that could perhaps be a compromise in the (un)checked exceptions-controversy. Each programmer could define an "unchecked"-filter. Perhaps it would best be viewed as a kind of lint.
    In any case, I have not found any tool, and it seems I can not do it myself with reflection, since it only gives access to declared exceptions, i.e., if the JDK-programmer decided not to put IOException in the signature of a method, then reflection can not see that the method may throw such an exception.
    Does anybody know how to do this?

    Douglas1024 wrote:
    Thank you for your time, but I am well aware how one uses exceptions in normal code.
    From an abstract point of view exceptions are simply a form of outputs from a method. Thus, if the goal is to write correct and easily verifiable code, in contrast to the vast majority of code that simply works reasonably, it is quite meaningful to know exactly what kinds of exceptions are thrown by a method and when.
    Please note my correction regarding IOException.Millions upon millions of lines of correct code have been written following these standard java exception principles. The notion that you can write "better" code by detailing every single unchecked exception that could possibly be thrown is ludicrous. In fact by handling unchecked exceptions you will in all likelihood do more harm than good, hence why they are unchecked in the first place.

  • Introduction of flow control and synchronization steps in Test Description

    Hi ALL,
              I am working on developing of Test Scripts in ATML standards. Can any one inform me how to introduce flow control (if, else, end, for, while, break etc)  and synchronization (wait etc) steps into the Test scripts. Thanks in advance.
    With Best Regards,
    Kalyan 

    I had a similar issue in a project I am working on. I'm not sure if I did this the "Best Practices" way or not, but it works perfectly.
    In the head area of my JSP I include the following:
    <f:view>
        <h:outputText id="refresher1" rendered="#{queryHandler.queryRunning}">
            <f:verbatim escape="false">
                <meta http-equiv="refresh"
                      content="5,<%=response.encodeURL(request.getContextPath()+
                              "/queryStatus.jsf")%>">
            </f:verbatim>
        </h:outputText>
        <h:outputText id="refresher1" rendered="#{queryHandler.queryFinishedRunning}">
            <f:verbatim escape="false">
                <meta http-equiv="refresh"
                      content="5,<%=response.encodeURL(request.getContextPath()+
                              "/queryResults.jsf")%>">
            </f:verbatim>
        </h:outputText>This puts a 5 second refresh meta in the header to direct the browser to the correct page based on the status of the query thread.
    There are many ways to accomplish the effect you want. I suggest putting all the controls into the JSP and making use of the rendered attributes instead of the JSTL conditionals to show the controls you want for the state of the application.
    -jeffhoward

Maybe you are looking for

  • Report should executed based on the radio buttons on the selection screen

    Hi everyone, Greets.................... My scenario is I have 2 selection screen blocks on same screen.. One selection screen block contains input parameters as follows Company Code  -  S_BUKRS Business Area -  S_GSBER Customer Code -  S_KUNNR Fiscal

  • App imitates sending out a virus over the network

    The last time I ran the Classic App called "Farallon Ping" which came with my old Farallon NC I bought years ago was back in 2003 or 2004 and I was told by IS of the University I was attending not to run it again as the app makes it appear to be send

  • Can you download third party apps or games for ipod nano 7th generation?

    I am trying to figure out if there are any games or app's that you can download or install on ipod nano 7th generation?? Is there any additional content of any kind that you can add to your ipod nano 7th gen.??

  • Internal Microphone Stopped Working

    My internal microphone has stopped working. I use Garageband frequently and one day, suddenly, it just stopped working. Even in the system preferences there are no bars to indicate any sound being monitored. This is very strange as I haven't dropped

  • Reg: No enries in SID table of attribute of a  Master data info object

    Hello SAP Gurus!!! I Hope everyone is doing good. I found some issues , when i loaded master data into master data info object in sap bi. I have an object which is holding master data (master data info object)---ZEMPID(employee id) I have attributes