Rethrowing the same exception - how, when and why?

Hi,
I have just gone through the Exception Handling chapter and found don't understand when should I use the rethrowing of same exception?
e.g.
catch(NullPointerException e) {
e.printStackTrace();
throw e;
or
catch(NullPointerException e) {
e.printStackTrace();
Throwable changedE = e.fillInStackTrace();
throw changedE;
I am not sure how, why and when should I use this syntax?
Any advice and a given example is much appreciated.
Thanks in advance.
gogo

Think about the information you would want when this exception occurs; if you rethrow the exception then the entire stack trace will be available which will allow you to find the root of the problem more easily than if you have filled in the stack trace at an intermediate point in the call graph. Never throw away information in an exception.
Note also that fillInStackTrace() does not actually create a new instance of the Throwable. It just returns the same instance but with it's stack trace modified.
There are two other points to note about your example:
First, catching NullPointerExceptions or any subclass of RuntimeException (except for the curseworthy NumberFormatException) is generally a bad thing to do. RuntimeExceptions usually indicate that something is wrong with your code or with the VM and catching them is just masking the real problem. They're not like checked exceptions (subclasses of Exception that are not RuntimeExceptions) which can occur because of something 'unexpected' happening in the environment which has nothing to do with bad code and for which recovery from the problem is often possible.
Second, consider whether you really want to catch an Exception anyway. Exceptions should only be caught when:
a) you want to try to recover from the problem i.e. you can handle the exception
b) you want to transform the exception into something more meaningful to client code, i.e. if the exception comes from deep in some library code and you can't handle the exception but the actual class of exception won't be meaningful to the client code, then you might want to create your own Exception subclass and throw an instance of that in place of the original exception. If you do this, then you should chain the original exception so that you still preserve all the stack information and the original message (this is why all Throwables in JDK 1.4 have constructors that take a Throwable 'cause' parameter)
Lance

Similar Messages

  • My dad and i use the same apple id, when he recieves a call, hes phone and my phone ring at the same time, why?

    my dad and i use the same apple id, when he recieves a call, hes phone and my phone ring at the same time, why?  and how do i fix this

    Settings > FaceTime > iPhone Cellular Calls > OFF

  • I am changing from Word to Pages. I have created my custom template with all my styles etc and that is what comes up when I go for a New Document. Fine. How do I get it to use the same Custom Template when I use Pages to open a Word document?

    I am changing from Word to Pages. I have created my custom template with all my styles etc and that is what comes up when I go for a New Document. Fine. How do I get it to use the same Custom Template when I use Pages to open a Word document?

    The template is a document in itself, it is not applied to an existing document whether it is a Pages document or a Word document converted to a Pages document.
    You would need to either copy and paste content, using existing styles, or apply the styles to the converted Word document.
    You can Import the Styles from an existing document and those imported Styles can be used to override the current document's styles:
    Menu > Format > Import Styles
    The process is simplified if the styles use the same names, otherwise you will need to delete the style you don't want and replace it with the one that you do want when asked, then the substitution is pretty straightforward.
    Peter

  • My father updated his iPhone and once he did that he would receive all of my texts and iMessages, is that because we are on the same iCloud account? And if that's why how can I remove it or make it so he doesn't get all my messages

    My father updated his iPhone and once he did that he would receive all of my texts and iMessages, is that because we are on the same iCloud account? And if that's why how can I remove it or make it so he doesn't get all my messages

    you can change the accounts of different apps in the phone's settings menu.

  • When I connect my ipod to my computer it opens my documents and won't show up in my itunes and I have unistalled then reinstalled itunes and reset my ipod twice and it stills does the same thing how can I make it so that it shows up in my itunes?

    When I connect my ipod to my computer it opens my documents and won't show up in my itunes and I have unistalled then reinstalled itunes and reset my ipod twice and it stills does the same thing how can I make it so that it shows up in my itunes?

    Try
    iOS: Device not recognized in iTunes for Windows
    I would start with              
    Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP
    or              
    Removing and reinstalling iTunes and other software components for Windows Vista, Windows 7, or Windows 8
    Before you reinstall the Apple software, also remove iCloud vi Control Panel Remove programs. The reinstall the Apple programs
    New cable and different USB port?
    Runs this and see if the results help with determine the cause
    iTunes for Windows: Device Sync Tests
    Try on another computer to help determine if computer or iPod problem

  • How is the resolution variable or when would we change the resolution of an image and why?

    How is the resolution variable or when would we change the resolution of an image
    and why?

    It all depends on the output:
    * for viewing on screen 90 -120 ppi
    * for printing on a laser printer 180  -300 ppi
    * for printing on a desktop printer 240 - 300 ppi
    Some people claim 360 ppi is optimum but I don't see any difference compaired to 300 ppi at least not with the naked eye...

  • Why am I getting two different conversations when the same person txts me and sends me an I message? I thought they should be in the same conversation?

    Why am I getting two different conversations when the same person txts me and sends me an I message? I thought they should be in the same conversation?

    I'm experiencing something similar. My conversations are kept together but if the screen is opened to a conversation and I receive a text from that person it doesn't show up on the screen. The message alert in the upper corner indicates a new text but I have to back out of the screen and go back in to read it.

  • When I sign on to Safari, AOL appears and ADware starts streaming. The same thing happens when i go onto Chrome and sign on to AOL. How can I fix/ Thank you

    When I sign on to Safari, Aol appears with streaming adware. The same thing happens when I use Google Chrome and sign on to Aol mail. Is there anyway I can block ads and prevent safari from directing me to AOL without requesting it? I have A MacPro, Yosemite (10.10.2). Thank you

    First try
    Remove unwanted adware that displays pop-up ads and graphics on your Mac
    Next:
    Adwaremedic: Removes all known adware from your Mac
    If you can't download it since the malware is preventing it then see:
    https://discussions.apple.com/docs/DOC-7792

  • When and why (how) use the exit RSR00003 (EXIT_SAPLRRS2_001)

    Boa tarde, expert´s ...
    I tried to find documentation about exit RSR00003, but I didn´t found ...
    I want know when and why a have to use this exit ...
    Muito obrigado,

    Hello,
    The exit is only for Internal SAP use this is why you don't find any documentation for it. So you don't need
    to use it, see the information in the SAP note 153562.
    Best Regards,
    Des

  • My macbook pro's screen display has suddenly gone into a strange colour setting where everything appears in a kind of infrared colour palette an I can;t seem to change it back.  It's the same for all icon and websites, does anyone know how to restore?

    My macbook pro's screen display has suddenly gone into a strange colour setting where everything appears in a kind of infrared colour palette an I can;t seem to change it back.  It's the same for all icon and websites, does anyone know how to restore?

    Wow!  I think I had this same issue just last night.
    I was cleaning my macbook pro retina on the outside.  Then I opened it up and was wiping dust off the monitor and I can't pinpoint exactly when, but the colors changed suddenly.  It looked super strange, it was like green halo's and it looked worse when looking at it at an angle.  Of course I took no pictures!!!  I was freaking out that my 2 grand laptop was busted and I somehow removed a protective film or something.
    But I digress...  The image looked very green and spacey, it was almost a neat effect.  After about 5 minutes it started to look a little more digital though.  There were straight lines of this halo effect on the edges and top.  After about 10 minutes it turned into a predominate issue with the blacks on screen.  I could open a web browser and it was unnoticable on a white background.  After about 15 minutes, you could only barely see the green cloud effect if you looked at the monitor from an extreme angle.  After about 20 minutes, it was completely back to normal, I almost feel paranoid like I see a halo or something strange.  But I believe that might be all in my head now.
    So yerp, lemme know what you guys figure out.

  • I have a DAQ Assistant configured to read multiple channels at the same time. When I wire a graph indicator to the output, I see all of my signals jumbled together. How do I split them up into seperate signals?

    I have a DAQ Assistant configured to read 2 channels at the same
    time. When I wire a graph indicator to the output, I see the 2
    signals jumbled together. How do I split them up into seperate signals?
    When I wire any type of indicator it is showing just one output of a single channel.
    I want 2 indicators showing 2 different signals as expected from the 2 channels configured. How to do this?
    I have tried using split signal but it end up showing only 1 output from 1 signal in both the indicators.
    thanks in advance.
    Solved!
    Go to Solution.

    Yes you are right. I tried that but I did not get the result.
    I just found the way. When we launch split signal, we should expand it (split signal icon) from above and not from below. It took me a while to figure out this. 
    thanks 

  • How to use the same image map over and over

    Sorry, I posted this a couple of years ago and got a good answer by Murray. I'm so rusty with it, I can understand how it works anymore.
    Question:
    I have a large jpeg image map for a hundred pages. The jpegs are all the same except I changed the city name for each one.
    So for each corresponding htm page, the 4-5 links out are the same.
    Waht is the trick to not have to create by hand hotspots? thanks.
    I have previous notes, but I don't understand anymore, (too rusty) what they mean:
    The good news is that you really don't need a template at all.
    Just open one of your existing pages in DW, select that central image, browse to select the correct replacement image, and save the page with a new name.  It will have all of the image maps already there, from the original image.  One and done as they say."
    My old interpretation of this:
    select the large jpeg and then in link field drag over to the new city jpeg

    Ok, Nancy, code copy/ paste did work fine.
    what does this mean:
    "Change the image in the properties panel to display your new image."
    (the image is displaying ok)
    NEverthesless, I think I got Murrays old notes.
    Here is my new version of Murrays writing, easiest way I think:
    You open up a pre-existing html, say Chicago. Then drag over with pointer to the new jpeg you want (Buffalo). It replaces Chicago with the buffalo jpeg, all links work perfectly. Then do a save as called Buffalo.

  • How to share the same Database Connection when using several Task Flows ?

    Hi All,
    I’m using JDev 11.1.1.3.0.
    I’m developing ADF Fusion Applications (ABC BC, ADF Faces…)
    These applications are deployed on a Weblogic server.
    Each application has only one Application Module.
    All Application Modules have the same connection type defined: JDBC DataSource : jdbc/GCCDS
    It is working fine.
    I’ve also developed Task Flow Applications for small thinks that are reused in multiple main applications.
    Each Task Flow Application has also one Application Module with the same connections type as main applications.
    All these task flows are deployed to JAR file (ADF Library JAR File) and are reused on my main applications. (drag and drop from the Resource Palette to ADF Regions….).
    There are some parameters passed to Task Flows, so that they can filter data depending on which main applications they are called from.
    Everything is working perfectly.
    All my main applications are using more and more task flows. Which is nice for the reusability etc…?
    Only ONE PROBLEM: DATABASE CONNECTIONS.
    Every Task Flows service made a database connection. So one user may have 10 database connections for the same adf page. And when there are 100 users that are working at the same time, it becomes a problem.
    How to share the same database connections for the main applications and all task flows which are used in the main application?
    Best Regards
    Nicolas

    Hi John,
    When I open a ADF Library JAR file of one of my task flow. (gcc_tf_recentSites.jar)
    I can see TF_RecentSitesService.xml and TF_RecentSitesServiceImpl.class in gcc_tf_recentSites.jar\mu\gcc\tf\recentSites\model\service folder
    + bc4j.xcfg in gcc_tf_recentSites.jar\mu\gcc\tf\recentSites\model\service\common folder.
    bc4j.xcfg details are
    +<?xml version = '1.0' encoding = 'UTF-8'?>+
    +<BC4JConfig version="11.1" xmlns="http://xmlns.oracle.com/bc4j/configuration">+
    +<AppModuleConfigBag ApplicationName="mu.gcc.tf.recentSites.model.service.TF_RecentSitesService">+
    +<AppModuleConfig DeployPlatform="LOCAL" jbo.project="mu.gcc.tf.recentSites.model.TF_RecentSites_Model" name="TF_RecentSitesServiceLocal" ApplicationName="mu.gcc.tf.recentSites.model.service.TF_RecentSitesService">+
    +<Security AppModuleJndiName="mu.gcc.tf.recentSites.model.service.TF_RecentSitesService"/>+
    +<Custom JDBCDataSource="jdbc/GCCDS"/>+
    +</AppModuleConfig>+
    +<AppModuleConfig name="TF_RecentSitesServiceShared" ApplicationName="mu.gcc.tf.recentSites.model.service.TF_RecentSitesService" DeployPlatform="LOCAL" JDBCName="gccdev" jbo.project="mu.gcc.tf.recentSites.model.TF_RecentSites_Model">+
    +<AM-Pooling jbo.ampool.maxpoolsize="1" jbo.ampool.isuseexclusive="false"/>+
    +<Security AppModuleJndiName="mu.gcc.tf.recentSites.model.service.TF_RecentSitesService"/>+
    +</AppModuleConfig>+
    +</AppModuleConfigBag>+
    +</BC4JConfig>+
    So, it seems that the Application Module is packaged with the task flow....
    Is it normal ?
    Regards
    Nicolas

  • How do i extend airplay to stream music at the same time to AEX and ATV2

    I have a new ATV2 and an AEX, my macbook, 2 Ipod touches and an Ipad2.
    I figured out how to setup my ATV2 and airplay through my macbook and my touches. My ATV2 is in my living room on a Yamaha 6.1 receiver with 2 channels. I have 6 speakers in my living room on channel A and a speaker in my bathroom on channel B.
    So....I decided to grab an extra Bose speaker and bring it to my foyer/kitchen and hook it up to my AEX since i cant hear the music too well when im cooking or in my office from the speakers in the living room.
    I setup the AEX to connect direct to the speaker. When Im on Itunes (either mac book or touch) i only get two options to airplay, AEX or ATV2.
    My question: How do I extend airplay to stream music on BOTH AEX and ATV2 with the same music at the same time?
    Please and thank you!

    As you are already aware both the 802.11n AirPort Express Base Station (AXn) and ATV2 are AirPlay "speakers." When both devices are properly connected to your home's wireless or wired network, both should show up in iTunes as in your case. Also the iTunes AirPlay speaker selector should provide you with an option to choose multiple speakers. As a minimum, you should see: Computer, the AXn, the ATV2, and the Multiple Speakers options. Is this not the case?

  • Hi  can any body please tell me how to open the .exe files in mac and why it is not supported with unarchiever app , also i am not able to run and dvd's in my mac its not accepting any cd's or dvd'd why do i need to do some settings for it ?

    Hi  can any body please tell me how to open the .exe files in mac and why it is not supported with unarchiever app , also i am not able to run and dvd's in my mac its not accepting any cd's or dvd'd why? do i need to do some pre defined  settings to run the cd's and dvd's ?

    A .exe file is a Windows executable. OS X does not run Windows programs. If you need to use .exe files then you will need to install Windows on your Mac:
    Windows on Intel Macs
    There are presently several alternatives for running Windows on Intel Macs.
    Install the Apple Boot Camp software.  Purchase Windows XP w/Service Pak2, Vista, or Windows 7.  Follow instructions in the Boot Camp documentation on installation of Boot Camp, creating Driver CD, and installing Windows.  Boot Camp enables you to boot the computer into OS X or Windows.
    Parallels Desktop for Mac and Windows XP, Vista Business, Vista Ultimate, or Windows 7.  Parallels is software virtualization that enables running Windows concurrently with OS X.
    VM Fusionand Windows XP, Vista Business, Vista Ultimate, or Windows 7.  VM Fusion is software virtualization that enables running Windows concurrently with OS X.
    CrossOver which enables running many Windows applications without having to install Windows.  The Windows applications can run concurrently with OS X.
    VirtualBox is a new Open Source freeware virtual machine such as VM Fusion and Parallels that was developed by Solaris.  It is not as fully developed for the Mac as Parallels and VM Fusion.
    Note that Parallels and VM Fusion can also run other operating systems such as Linux, Unix, OS/2, Solaris, etc.  There are performance differences between dual-boot systems and virtualization.  The latter tend to be a little slower (not much) and do not provide the video performance of the dual-boot system. See MacTech.com's Virtualization Benchmarking for comparisons of Boot Camp, Parallels, and VM Fusion. Boot Camp is only available with Leopard or Snow Leopard. Except for Crossover and a couple of similar alternatives like DarWine you must have a valid installer disc for Windows.
    You must also have an internal optical drive for installing Windows. Windows cannot be installed from an external optical drive.

Maybe you are looking for

  • Package view error

    Interesting product ... I've tried to load one of our larger and "troublesome" packages into the product. While the initial load worked, when I tried to choose "details" on the package body things started to hang. Same went for grants etc. When I fin

  • ABAP OO question

    Hi, Can someone please explain me the concept withe the below behavior ? System : SAPCRM 20007. Class : CL_BT311H_C_CSROVERVIEW_IMPL Super Class : CL_BT311H_C_CSROVERVIEW.(A) Super class of A : CL_CRM_UIU_BT_H_OVW_VIEWSET (B) Method Do_Handle_event i

  • How to install Windows XP on MacBookPro

    How do I install Windows XP on my MacBookPro? Do I have to buy Windows XP or can I use the cd that came with my PC which has XP on it? Do I just put the cd in and follow the instructions?

  • IT0028

    HEY, In IT0028, I have copied the examination area '08' Blood group & customize the new one with code '00' Blood group. While taking a report of Blood group through Adhoc Query, it shows me blank as otput even after selection of all the input from In

  • STACK/GROUP PHOTOS BY LIGHT CONDITION

    Is there any method to group/stack the photos by the light condition? I thought something about grouping by histogram similarities... what I want is a way to put together bright photos, and the dark ones... in a way I can just adjust one and sync. TH