Throws statement, why exactly it is used?

hi friends,
I tried to make this thing clear to me searching a lot across internet but still not found any such article.
would you please tell me why exactly we use throws statement in a method definition?
however, I know this much that using this we actually declare a method to throw some specified exceptions.
but why we do this? what is the advantage over if we catch exceptions manually inside method body?
please give me a simple explanation with examples
regards
san

There are some cases where you code should handle an exception. For example if you ask the user to enter a number and, when you try to convert the String he entered to a number you get a NumberFormatException, obviously you don't want the program to crash, you want to ask again. There are other cases where an exception indicates a fault in the program itself and, generally, you should not deal with these but allow the program to crash and print a stacktrace to aid your debugging.
In general the first kind are supposed to be "checked" exceptions, i.e. those that require a throws clause entry, while the latter are unchecked.
When it does make sense for the program to deal with the exception there's generally a most logical level of control at which to deal with it. For example suppose you have an exception thrown in a loop. Should the exception be handled inside the loop, or should it cause the loop to terminate before being handled. You may need access to local variables to process the exception properly. A try - catch statement requires the same kind of strategic thinking as any other control structure.

Similar Messages

  • Why I Can't use procedure in select statement

    Why I Can't use procedure in select statement

    We can use function in select statement but we couldn't use procedure with one out parameters in select statement... You can use Function because they are designed for this but procedure are not. Functions can return value (without OUT parameter) which can be used in SELECT whereas procedures do not have such concept. As you can see in the above post you can not call even functions also if it has any out parameter.
    I have just trying to use procedure in select statement ..for this I require technical answer..The technical answer is because conceptually procedure is for doing set of operation, performning DMLs on the tables , whereas functions are for processing and producing a single result. Functions are basically for not using INSERT/UPDATE/DELETE in it. That is the reason they are allowed to be used in SELECT because conceptually they are not supposed to do any data changes.
    Regards,
    Avinash

  • HT204032 Why can you not use powernap with a custom order iMac with solid state?

    Why can you not use powernap with a custom order iMac with solid state?
    Find it quite ridiculous that a 3 year old mba supports it and not a new iMac

    Agreed.  Why wouldn't you want your Photostream updated while your iMac is sleeping?  I am bummed about this.

  • Since downloaded ios7 on ipad 3G , I can only use it in the state of GOA, INDIA, where I live. Why can't I use it outside GOA ?

    Why can't I use my ipad 3G outside my living area since I've downloaded IOS 7 ? It's frustrating

    Check with your service provider and see if it affected something in their profile.

  • Throw statement (page 189)

    Hi,
    I'm not sure about the purpose of the throw statement.  What exactly does it do in the following example?  Does it throw the error message on the screen?  The manual is silent about what the throw statement does upon execution.
    The throw statement 
    Flash Player and Adobe AIR throw exceptions when they encounter errors in your application at run time. In addition, you can explicitly throw exceptions yourself using the throw statement. When explicitly throwing errors, Adobe recommends that you throw instances of the Error class or its subclasses. The following code demonstrates a throw statement that throws an instance of the Error class, MyErr, and eventually calls a function, myFunction(), to respond after the error is thrown:
    var MyError:Error = new Error("Encountered an error with the numUsers value", 99);
    var numUsers:uint = 0;
    try { if (numUsers == 0)
         { trace("numUsers equals 0"); } }
    catch (error:uint) {
         throw MyError; // Catch unsigned integer errors. }
    catch (error:int) {
         throw MyError; // Catch integer errors. }
    catch (error:Number) {
         throw MyError; // Catch number errors. }
    catch (error:*) {
         throw MyError; // Catch any other error. }
    finally {
         myFunction(); // Perform any necessary cleanup here. }
    Notice that the catch statements are ordered so that the most specific data types are listed first. If the catch statement for the Number data type was listed first, neither the catch statement for the uint data type nor the catch statement for the int data type would ever get executed.

    Why unwise?
    I have no particular need to do anything at this point.  I'm just studying off the user manual and on page 188 is where that example is shown.   By the way, do you know how for me to copy and paste from the user manual and still retain the tabs and return carriage?
    Here's the complete excerpt:
    Displaying a simple error message
    One of the biggest benefits of the new exception and error event model is that it allows you to tell users when and why an action has failed. Your part is to write the code to display the message and offer options in response.
    The following code shows a simple
    try..catch
    statement to display the error in a text field:
    package
    import flash.display.Sprite;
    import flash.text.TextField;
    public class SimpleError extends Sprite
    public var employee:XML =
    <EmpCode>
    <costCenter>1234</costCenter>
    <costCenter>1-234</costCenter>
    </EmpCode>;
    public function SimpleError()
    try
    if (employee.costCenter.length() != 1)
    throw new Error("Error, employee must have exactly one cost center assigned.");
    catch (error:Error)
    var errorMessage:TextField = new TextField();
    errorMessage.autoSize = TextFieldAutoSize.LEFT;
    errorMessage.textColor = 0xFF0000;
    errorMessage.text = error.message;
    addChild(errorMessage);

  • Why doesn't SAP use SAPUI5 for this and that

    This is my personal opinion about this topic! Again and again I stumble about this and now I want to share some of my thoughts about this topic. I want to share this from a point of view, when I was not a SAP Employee - I worked at a SAP Partner company - because this best reflects the view from the outside.
    1. SAP "wants" us to use SAPUI5
    I don't think that "wants" is the right word - the right word is offers! In terms of: hey now even included in your license and open sourced (because you wanted it so). Look - we build sooo many Fiori apps with it - and put in some great enterprise features (right to left, accessibility, translation, ...) and it is responsive. So if you want to build Fiori-like "apps" - there you go - this is your technology to go! This is what I understood.
    I was very very very happy that it was build with open standards. But the main point for me another thing - (because I worked with Sybase Unwired Platform and SAP Mobile Platform) OMG an open data protocol!!! OData FTW! I could use ANY front-end technology and consume SAP data - the protocol is REST based - a dream came true. And so I did - yes I played around with Sencha Touch and OData, I used data.js and used it in a standard HTML5 application. We played around with an iOS application we already had and consumed the data. I feed the data into d3.js. I prototyped around with SAPUI5 and I have build apps with it. Brilliant, so I could choose whatever UI technology I wanted.
    I always had the feeling, that SAPUI5 was meant for B2E applications - and building many of that - and they should look and feel the same and I can theme the apps. I can use it when I want to make my applications SAP like - so that the user thinks the apps are all the same and everything fits nicely into the Fiori launchpad - great if you want to build partner apps. In my ex company we won a SAP Pinnacle Award - for a native iOS app, no SAPUI5 in sight - but we have received an award, so SAP did not "want us" to use SAPUI5 ;-)
    2. Is it the right UI technology for everything?
    At my ex-company I was dealing with mobile applications and web apps. I always knew that I get the best user experience when I write a real native application and if you want it to look like in a very specific way with awesome UI --> you would not do it with a write-once-run-everywhere HTML5 super-styled wrapped (phone gap/cordova) app - you would write the apps for the specific platform and it should feel like it was written for the platform. SAP offered us the SAP Fiori Client that I could enhance the user experience for the Fiori apps, but I was never told to use SAPUI5 it for everything.
    The same discussion goes on with: why was the new SAP website not build with SAPUI5, or the UX Explorer (eat your own dog food), or a useful internal app - why Angular, or the other way around why do we even use SAPUI5 and not Angular JS itself. Back to the past - SAP did never tell me to build a website with it, or to build something tiny and small with it (a widget) - or to enhance parts of a website with it - or to build something super-specific with it.
    And yes maybe the UI in a mobile app was not SAPUI5 but do you know if it uses Gateway with OData or the SAP Mobile Platform, was the API managed with Apigee, was HCI involved in getting the data from different sources, was it maybe wrapped with SAP Mobile Secure, did it maybe use a HANA backend or some of its features (predictions, text analytics, ...) - are some backend parts maybe hosted on HCP - who knows? So yeah, maybe other SAP technology was involved which you don't see, but in the end it made your life simpler.
    Instead of arguing around why this and that was used for this and that - can we save our energy and instead look at the result - which is all what counts - that it was the right UI technology with the right user interface which makes the user happy? I stated something like - does Google use AngularJS for everything? Nope. They offer us something great we can use. Right, maybe AngularJS is not as important for Google like SAPUI5 is for us. But we have something with which we can build our day-to-day business apps with and we do so.
    3. We missed great opportunity in not using SAPUI5 for this and that
    Let's think about how projects are going: you want something, you look at the costs, you choose most efficient option. Yes this could mean reusing an existing native application which was written long ago and you pimped it up. Or you had outsourced it to a company which wrote a similar app. Or you bought the source code. Or you have some cheap internal staff which could do it (students, trainee), or you could outsource it cheaply. Or all you have is people with experience in this and that technology. Or it must look in a very very specific way (because marketing says so) and you go native. Or it maybe should even differentiate itself and should look NOT like a Fiori app. And no - I don't think - this is my employees view - we are not for example an event app producer. We normally build business applications. And I don't think that we can write an app from scratch "just" for an event in a certain technology. Yes it would be nice if this and that would use SAPUI5, I think if it would be possible in terms of time and costs and UI wishes and hundreds of other factors we would do it with SAPUI5.
    Working at the partner SAP showed me over 50 Fiori apps, now hundreds of Fiori apps are released. SAP now showed that SAPUI5 is going big with S/4HANA. We have seen the Simple Finance solution. I was walking around at the CeBIT this year and I was impressed myself which cool apps and screens have been shown with SAPUI5. I used the SAPUI5 app on a Samsung Smart Watch myself. The SAP Web IDE itself is built with SAPUI5 in its heart. I don't need any other "proves" that SAPUI5 is great. I have seen great use cases for it, but I also know myself when I would use other stuff.
    4. My conclusion
    There is never every anything which can cover all different use cases. One-size-fits-all clothes also does not fit for everyone even if it says so. If someone creates something great don't judge it by the UI technology. Judge it by the experience and the value it creates. There are reasons why this and that was chosen. Use what fits your needs best with your requirements. Make the end user happy!

    Hey Denise,
    Thanks for pulling this discussion into SCN. Makes it much easier to discuss compared to Twitter. But I also have to apologize in the beginning that my answer now exceeds 140 characters by 50 times.
    Let me share my thoughts and personal opinion as well. I will try to look at it from a strategic point of view, as you – as the technical UI5 expert - have already covered the technical perspective.
    SAP recommends using SAPUI5 where it fits to customers’ requirements
    Let me begin with a clear statement from my perspective: It makes no sense that SAP takes customer decisions.
    Of course, customers expect SAP to help them with their strategies and decisions and of course we are helping. But at the end, the decisions have to be taken by the customer who needs to take the specific conditions of the company into account. The most important condition in the context of UX is the end user. But we shouldn't forget the business strategy as the most important influence factor. I’m not saying that technical decisions are completely unimportant, but I would like to point out that other things are more important for a company.
    As a result, it wouldn't make a lot of sense if SAP would just want every customer to use SAPUI5. To me, customers need recommendations leading to solutions that satisfy their needs and requirements.
    There is not that one UI technology that serves all needs
    This headline might be a challenging statement and I can already imagine reactions to it. But in fact I can confirm this sentence easily. You always have to combine different technologies. Some of them are from SAP others not. The selection and combination of these technologies is different from customer to customer because the requirements are different. There are still reasons to use Web Dynpro ABAP and I’m still recommending SAP NetWeaver Business Client, POWL (Power Lists), WDA Chips, FPM based on the given environment of the customer. And obviously there are also reasons for UI5.
    SAP already proves the usage of SAPUI5
    In general, I see two different use cases here: Developing custom applications vs. adopting applications from SAP.
    In the one case, customers want recommendations on development environments and UI technologies that consider their development requirements and existing conditions (e.g. existing skills, given implementations). SAPUI5 is a great UI technology and there are some special aspects that make the decision obviously easy. If I want to create simple business applications that can be connected with my SAP system easily, especially in combination under responsive conditions on multiple devices and targeted for casual and/or occasional users UI5 might be the right choice for many.  Exactly this pattern is what many customers are searching for these days. So, the recommendation for UI5 comes quite often.
    Whether or not SAP proves the usage of SAPUI5 in their own world is to me more connected to the use case where customers want to adopt SAP applications. And in deed, SAP is using SAPUI5. There are hundreds of SAP Fiori applications that have been built with SAPUI5 and there have been a lot of other applications developed using SAPUI5, too. And again, there is a huge need for applications for casual and/or occasional users, so that’s a big reason for SAP to create such applications.
    Websites vs. Business Applications
    This discussion was triggered by some statements in twitter, that SAP sites such as sap.com, SAP UX Explorer or the latest mobile conference app are not developed using UI5. Actually I see these to be websites but not business applications. I have never told a customer to build a website in UI5 and I would continue to do so.
    Maybe we need to discuss the difference between a website and a business application. I guess it is not easy to find a common understanding here, as the borderlines between several worlds have disappeared in the last years.
    Some years ago it was more or less easy to differ between:
    Native desktop applications running on a specific desktop OS
    Native mobile applications running on a specific mobile OS
    Browser-based applications running in specific browsers
    Websites, basically running on many browsers
    In the first three categories we saw business applications. 1 and 2 were selected especially when specific functions of the device and OS where needed to be accessed (for example the camera of the mobile device, the fast rendering capability of the desktop). 3 was also used for business applications but in most cases on desktop browsers.
    Today, one can develop browser-based applications that look like native applications and even can access the devices like native applications. Responsive design breaks the borderlines even more. Now, browser-based content can be rendered perfectly on a desktop browser as well as on a mobile phone and a user might even not be able to judge whether it was originally intended to be developed for the one or the other.
    So maybe there is no big difference anymore between websites and browser-based applications. But there is still a difference between browser-based applications and browser-based business applications, where additional requirements such as integration into business systems are drivers. Here I see SAPUI5 as a very cool UI technology.
    That’s just my 2 (personal) cents,
    JJ

  • Why can't I use my previous MobileMe email address instead of creating a new one?

    Why can't I use my previous MobileMe email address instead of creating a new one?  When signing up for iCloud I'm asked to choose an email address [email protected]  I am already using an @me address via moblileme.  When i input that address it states that that address is already taken.  Try picking a new one.  I don't want a new one I want to use my mobileme address.  How can that be done?

    It appears you set up a new iCloud account rather than migrating your MobileMe account over to iCloud.  I migrated everything over this morning and am still using my old MobileMe email address.
    Check to see if you can migrate rather than open a new account.
    Lew

  • Why can't I use my internet, when other Apple products Can?

    why can't I use my internet, when other Apple products Can?

    Hi helen xia,
    Which OS are you using? Please let us know the exact error message.
    Regards,
    Romit Sinha

  • Throw statement equivalent in ABAP Objects

    Hi All,
    I am trying to raise an exception and use a throw statement after catch inside try endtry in ABAP objects. Later i understood that there is no throw statement defined in ABAP objects. Could anyone help me out to understand the equivalent throw statement in ABAP and how to use in raise exception. I am pasting my code below for reference.
    try.
        CATCH Zxx_EXCEPTION into err.
         write:/ err->local_text.
        message err->LOCAL_TEXT type 'I'.
         if err->local_text = ZIF_XXXX~BUSOBJLOCKED.
          throw CX_AI_APPLICATION_FAULT.
    endtry.
    Thanks
    Deno

    Hello Deno
    The TRY/CATCH logic of ABAP-OO is pretty much the same like in Java. Instead of throwing exception we have to raise them.
    Method execute somewhere raise an exception of class zcx_myexception.
    method execute.
      if ( condition = abap_true ).
      else.
        RAISE EXCEPTION TYPE zcx_myexception
          EXPORTING
            textid = ...
            <parameter> = ...
      endif.
    endmethod.
    TRY.
      call method go->execute( ).
      CATCH zcx_myexception INTO lo_error.
    * Do error handling
    ENDTRY.
    If the method that calls go->execute does not surround the method call by TRY/CATCH then it must define the exception class in its interface and, thereby, propagate the exception to the next higher level calling method.
    Regards
      Uwe

  • Why can't I use links within my email messages? When a link is clicked, nothing happens--it doesn't go to that specific website.

    Why can't I use links within my email messages? When a link is clicked, nothing happens--it doesn't go to that specific website.

    HI Ana ...
    I had FB working again two days ago, and yesterday in mid-serve Safari just "couldn't find the server" once more...
    That's a different issue...
    First, if you can just use English, open System Preferences > Language & Text then select the Language tab. Drag English to the top of the list then restart your Mac.
    Now for the server issue. Try using Open DNS. That shold help the "couldn't find the server" issue...
    Open System Preferences / Preferences then select the Network tab. Click the Advanced tab then click the DNS tab.
    Click +
    Enter these numbers exactly as you see them here.
    208.67.222.222
    Click +
    208.67.220.220
    Then click OK.
    Try accessing Facebook on Safari now.

  • Why index is not used by this table

    Dear all,
    Currently I'm facing problem with tuning one sql statement.
    It shows that full table scan in ZTLTBC_FILTER cost 15:19.
    But in table ZTLTBC_FILTER, it have index with field
    index 1    MANDT INT_NAME FNAME VALUE
    index 2    MANDT EXEC_ID COUNTER
    index 3    MANDT INT_NAME VALUE
    the last statistic date for these index is three months before
    Could you please help to find out the reason why index is not used?  statistics are old or small distinct value for field INT_NAME?
    How to solve this full table scan problem?
    Thanks & Regards,
    Chris
    sql statement
    SELECT T_00."MANDT",T_00."EXEC_ID",T_00."COUNTER",T_00."FNAME",T_00."INT_NAME",T_00."VALUE"
    FROM "ZTLTBC_FILTER" T_00
    WHERE T_00."MANDT"=:A0 AND T_00."INT_NAME"=:A1 AND EXISTS
    (SELECT T_100."INT_NAME"
    FROM "ZTLTBC_MIRR_BUFF" T_100
    WHERE T_100."MANDT"=:A2 AND T_100."INT_NAME"=:A3 AND T_100."EXEC_ID"=T_00."EXEC_ID" AND
    T_100."COUNTER"=T_00."COUNTER")
    | Id  | Operation            | Name               | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |                    |       |       |       |   176K(100)|          |
    |*  1 |  HASH JOIN RIGHT SEMI|                    |  9958K|  1111M|   598M|   176K  (2)| 00:17:53 |
    |*  2 |   INDEX RANGE SCAN   | ZTLTBC_MIRR_BUFF~0 |  9958K|   484M|       |  6265   (1)| 00:00:39 |
    |*  3 |   TABLE ACCESS FULL  | ZTLTBC_FILTER      |    13M|   822M|       |   150K  (2)| 00:15:19 |
       1 - access("T_100"."EXEC_ID"="T_00"."EXEC_ID" AND "T_100"."COUNTER"="T_00"."COUNTER")
       2 - access("T_100"."MANDT"=:A2 AND "T_100"."INT_NAME"=:A3)
       3 - filter(("T_00"."INT_NAME"=:A1 AND "T_00"."MANDT"=:A0))

    Hello Bret,
    I'm using oracle 11.2
    Thanks & Regards,
    Chris

  • Why Interceptors are not used in Entity beans?

    Why Interceptors are not used in Entity beans?
    Interceptors can be used in MDB, Session bean but not in Entity bean....why so?
    Thanks,
    Rahul.

    Hi,
    why batch updations are not prefered in entity beansPlease refer the specification of ejb and find out what the entity bean is meant for.In short the emtity bean represents the object state which can be persisted.
    Talking regarding the batch updations does not make sense , also the entity bean represents the row of the table mapped to the Object(java Object).
    Regards
    Vicky

  • Why can't i use the rest of my money on my iTunes redeem money

    Why can't I use the rest of my money that I redeemed my I tunes card with.

    You do not state your issue and what happens when you try...
    So...
    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • HT201209 Why is it still using credit card for purchase?

    We have 2 devices, a new mini iPad, and an iPod touch, one is my sons but both are registered in my name and account info. We put 2 $15 dollar codes in and it says $30 credit. When my son buys a song on his iPod, It still takes it out of credit card.. Why is it not using gift credits?

    I have this question too. I have plenty of credit, yet it still shows a pending transaction on my credit card. I'm guessing/hoping it show the "pending" until its actually taken from the gift card, which may take 24-48 hours...this is usually the delay before receiving the email that states the transaction was made.
    Can anyone confirm this? Or let us know what is really going on???

  • When LR cannot read a photo, LR should state why

    The Warning dialog has a generic message but no explanation of why LR was unable to read the photo: "Lightroom has encountered problems reading this photo. You will not be able to make adjustments to the photo." This is not helpful, LR needs to state why.
    E.g. last time, I noticed they were two photos in Lab Color Mode, so I figured out LR cannot read files in Lab Color Mode; the Warning message should state it.

    This is pervasive in "modern" software: software detects a problem (and almost always knows what problem it has encountered), stops the process and tells you it stopped. But programmers are lazy beasts and it seems that it has become much too much effort for them to generate an error message with some meaning and possible circumventions, etc. There is software that will facilitate this process but it is just too demeaning ... especially since programmers are supposed to write good code and reporting errors reflects poorly, eh? Having been a mainframe assembler programmer for fifteen years I know it used to be unacceptable to detect an error and not report what the error was. But since the rise of Microsoft it appears that the convenience of the programmers has way surpassed the needs of the customers and Adobe is leaning this way. They use this same "technique" when they can't export an image ... "We didn't export it ... you try to guess why not!"

Maybe you are looking for