Return statement in a try catch block

Hi friends
Take a look in the code bellow
try
return (true)
finally
System.out.println("blabla");
If nothing strange hapens in the try code, the return statement will be achieved. In this case, what will hapen ? The code in the finally block will be executed ??
thanks

If nothing strange hapens in the try code, the return
statement will be achieved. In this case, what will
hapen ? The code in the finally block will be executed
??Yes. Hence the word "finally".

Similar Messages

  • How to get the returned error messages in the Try/Catch block in DS 3.0?

    A customer sent me the following questions when he tried to implement custom error handling in DS 3.0. I could only find the function "smtp_to" can return the last few lines of trace or error log file but this is not what he wants. Does anyone know the answers? Thanks!
    I am trying to implement the Try/Catch for error handling, but I have
    hard time to get the return the msg from DI, so I can write it to out
    custom log table.
    Can you tell me or point me to sample code that can do this, also, can
    you tell me which tables capture these info if I want to query it from
    DI system tables

    Hi Larry,
    In Data Services XI 3.1 (GAd yesterday) we made several enhancements for our Try/Catch blocks. One of them is the additional of functions to get details on the error that was catched :
    - error_message() Returns the error message of the caught exception
    - error_number() Returns the error number of the caught exception
    - error_timestamp() Returns the timestamp of the caught exception.
    - error_context() Returns the context of the caught exception. For example, "|Session Datapreview_job|Dataflow debug_DataFlow|Transform Debug"
    In previous versions, the only thing you could do was in the mail_to function specify the number of lines you want to include from the error_log, which would send the error_log details in the body of the mail.
    Thanks,
    Ben.

  • Can't find class because of try catch block ?!

    Hello,
    I'm using the JNI to use a java library from my c++ code.
    JNI can't find the "Comverse10" class below, but when i put the try catch block in createMessage in comment, FindClass succeeds ?!
    Unfortunatly i need the code inside the try block ;-)
    I tried a few things, but none of them worked:
    - let createMessage throw the exception (public void createMessage throws ElementAlreadyExistsException ), so there isn't a try catch block in createMessage => result: the same
    - make a "wrapper" class Comverse that has a Comverse10 object as attribute and just calls the corresponding Comverse10.function. Result: Comvers could be found, but not constructed (NewObject failed).
    Can someone tell me what is going on ?!
    Thank you,
    Pieter.
    //Comverse10 class
    public class Comverse10 {
    MultimediaMessage message;
    /** Creates a new instance of Comverse10 */
    public Comverse10() {
    public void createMessage() {
    TextMediaElement text1 = new TextMediaElement("Pieter");
    text1.setColor(Color.blue);
    SimpleSlide slide1 = new SimpleSlide();
    //if i put this try catch block in comment, it works ?!
    try{
    slide1.add(text1);
    catch(com.comverse.mms.mmspade.api.ElementAlreadyExistsException e){}
    MessageContent content = new MessageContent();
    content.addSlide(slide1);
    this.message = new MultimediaMessage();
    message.setContent(content);
    message.setSubject("Mijn subjectje");
    for those of you who are intersted: here's my C++ code:
    //creation of JVM
    HRESULT Java::CreateJavaVMdll()
         HRESULT HRv = S_OK;
    char classpath[1024];
         jint res;
         if(blog)     this->oDebugLog->Printf("CreateJavaVMdll()");
         strcpy(classpath,"-Djava.class.path="); /*This tells jvm that it is getting the class path*/
         strcat(classpath,getenv("PATH"));
         strcat(classpath,";D:\\Projects\\RingRing\\MMSComposer;C:\\Progra~1\\j2sdk1~1.1_0\\lib");     //;C:\\Comverse\\MMS_SDK\\SDK\\lib\\mail.jar;C:\\Comverse\\MMS_SDK\\SDK\\lib\\activation.jar;C:\\Comverse\\MMS_SDK\\SDK\\lib\\mmspade.jar
         //------Set Options for virtual machine
         options[0].optionString = "-Djava.compiler=NONE"; //JIT compiler
         options[1].optionString = classpath;                                        //CLASSPATH
         //------Set argument structure components
         vm_args.options = options;
         vm_args.nOptions = 2;
         vm_args.ignoreUnrecognized = JNI_TRUE;
         vm_args.version = JNI_VERSION_1_4;
         /* Win32 version */
         HINSTANCE hVM = LoadLibrary("C:\\Program Files\\j2sdk1.4.1_01\\jre\\bin\\client\\jvm.dll");
         if (hVM == NULL){
              if(blog) oDebugLog->Printf("Can't load jvm.dll");
              return E_FAIL;
         if(blog) oDebugLog->Printf("jvm.dll loaded\n");
         LPFNDLLFUNC1 func = (LPFNDLLFUNC1)GetProcAddress(hVM, "JNI_CreateJavaVM");
         if(!func){
              if(blog)     oDebugLog->Printf("Can't get ProcAddress of JNI_CreateJavaVM");
              FreeLibrary(hVM);     hVM = NULL;
              return E_FAIL;
         if(blog)     oDebugLog->Printf("ProcAddress found");
         res = func(&jvm,(void**)&env,&vm_args);
         if (res < 0) {
    if(blog)     oDebugLog->Printf("Can't create JVM with JNI_CreateJavaVM %d\n",res);
    return E_FAIL;
         if(blog)     oDebugLog->Printf("JVM created");
         return HRv;
    //finding Comverse10 class:
    HRESULT CALLAS MMSComposer::InitializeJNI(void)
         HRESULT HRv=E_FAIL;
         DWORD T=0;
         try
              if(blog)     oDebugLog->Printf("\nInitializeJNI()");
              bJVM = FALSE;
              jni = new Java(oDebugLog);
              if(jni->CreateJavaVMdll()!=S_OK){
                   if(blog)     oDebugLog->Printf("CreateJavaVMdll() failed");     
                   return HRv;
              jclass jcls = jni->env->FindClass("Comverse10");
              if (jcls == 0) {
    if(blog)     oDebugLog->Printf("Can't find Comverse10 class");
                   jclass jcls2 = jni->env->FindClass("test");
                   if (jcls2 == 0) {
                        if(blog)     oDebugLog->Printf("Can't find test class");
                        return HRv;
                   if(blog)     oDebugLog->Printf("test class found %08x",jcls2);
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10 class found %08x",jcls);
              jmethodID mid = jni->env->GetMethodID(jcls , "<init>", "()V");
              if (mid == 0) {
                   if(blog)     oDebugLog->Printf("Can't find Comverse10() constructor");
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10() constructor found");
              jobject jobj = jni->env->NewObject(jcls,mid);
              if(jobj==0)
                   if(blog)     oDebugLog->Printf("Can't construct a Comverse10 object");
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10 object constucted");
              //Create Global reference, so java garbage collector won't delete it
              jni->jobj_comv = jni->env->NewGlobalRef(jobj);
              if(jni->jobj_comv==0)
                   if(blog)     oDebugLog->Printf("Can't create global reference to Comverse10 object");
    return HRv;
              if(blog)     oDebugLog->Printf("global reference to Comverse10 object %08x created",jni->jobj_comv);
              bJVM=TRUE;
              HRv=S_OK;
         }     catch( IDB * bgError ) { throw bgError->ErrorTrace("InitializeJNI::~InitializeJNI",HRv, 0, T); }
              catch(...) { throw IDB::NewErrorTrace("InitializeJNI::~InitializeJNI",HRv, 0, T ); }
              return HRv;

    >
    I would guess that the real problem is that that the
    exception you are catching is not in the class path
    that you are defining.Thanks jschell, that was indeed the case.
    I don't have the docs, but I would guess that
    FindClass() only returns null if an exception is
    thrown. And you are not checking for the exception.
    Which would tell you the problem.Ok, i'll remember that. But what with exceptions thrown in my java code, the documents say
    // jthrowable ExceptionOccurred(JNIEnv *env);
    // Determines if an exception is being thrown. The exception stays being thrown until either the native code calls ExceptionClear(), or the Java code handles the exception
    so, what if the java code throws an exception and catches it, will i be able to see that in my c++ code with ExceptionOccurred ?
    or
    should the java method be declared to throw the exception (and not catch it inside the method)
    Again, thank you for your help, it's greatly appreciated !

  • How to use Try Catch Block in ABAP Like JAVA

    Hi Experts,
       I am using BAPI to post MIGO in one of my application. If the MIGO is successfully gets posted then BAPI returns no message, but if there is some error in posting then it returns an error message. Now I want to print that error message in catch block by calling method RAISE_ERROR_MESSAGE. How to use try catch block in ABAP. Please suggest with example.
    Thanks and Regards.
    Vaibhav Tiwari.

    Hi Vaibhav
    You may not catch exceptions returned by function module using try endtry block.
    It works well with the exception returned by methods.
    In case of function modules or BAPI what u can do is to check sy-subrc returned and give message accordingly. If it returns a structure like bapireturn then display message returned.
    in case of exception returned by a method,  do it like this...
    data: excep type cx_root.
    data: v_str type string.
    try.
    *any method call or division by zero (for ex)
    catch cx_root into excep.
    endtry.
    if  excep is not initial.
    CALL METHOD   excep->if_message~get_text
      receiving
        RESULT = v_str.
    endif.
    *display the value returned in v_str on screen

  • Compile time errors for large code in try-catch blocks

    Hi, Has anyone ever faced this problem of a compile time error, where the Java compiler returns with the following error that Code is too large for try block.
    I have about 5000 thousand lines in my try-catch block and am facing this problem. Please suggest possible solutions

    1) Are you sure that your try/catch blocks contain 5 million lines?! I seriously don't believe this.Sounds like generated code. The generator needs to be a bit cleverer. In particular, it seems to be generating repeated blocks of code that ought to be stuffed into methods somewhere.

  • Performance impact on using too much try catch block

    I have several questions here:
    1. The system that I'm developing requires to be high performance, but I am not sure how will try catch block affect overall performance.
    2. I wanted to know which would be more efficient (result in faster processing)
    Have several generic try catch OR catch all exceptions individually?
    ex:
    try {
    } catch (Exception e){
    }vs.
    try{
    } catch (MalformedUrlException me){
    } catch(SQLException){
    }3. Which one would be faster, one big try catch block or several small try catch blocks?
    ex.
    try{
    //read from io file
    //query database
    //parse data
    //write to file
    //query database again
    } catch(Exception e){
    //log exception
    }vs.
    try{
    //read from io file
    } catch(FileNotFoundException fnfe){
    //log exception
    try{
    //query database
    }catch(SQLException se){
    //log exception
    try{
    //parse data
    }catch(SaxParserException saxe){
    //log exception
    try{
    //query database again
    }catch(SQLException se2){
    //log exception
    try{
    //write to file
    } catch(FileNotFoundException fnfe){
    //log exception

    1. The system that I'm developing requires to be high performance, but I am not sure how will try catch block affect overall performance.Compared to what? You can't write an equivalent program that doesn't have a try-catch block, so the answer would have to be that it doesn't affect performance at all.
    2. I wanted to know which would be more efficient (result in faster processing)Have several generic try catch OR catch all exceptions individually?
    You still have it backwards. Do you need to do different things for different exceptions? If so, then that's what you have to do and there is no other code that might be "faster".
    Here's what you should do. Write the code that needs to be written. Don't leave out necessary stuff because of performance reasons. (If you left out all your code, the program would run much faster.) Then find out which parts of the program ACTUALLY take the most time and work on speeding them up.

  • Try Catch Blocks

    This may be too vague of a question but is it bad practice to use one large try catch block? In my mind it seems like it would produce "cleaner" code as far as programmer reading is concerned, but does it affect the program adversely?
    try {
    // code goes here
    } catch (somekindofexception e){
    // print exception e
    } catch (anotherkindofexception e){
    // print exception e
    } // continue for all possible exceptions

    bolivartech wrote:
    I was mistaken it looks like the particular function I was thinking of throws 3 kinds of RuntimeExceptions, but the same idea applies right?
    try {
    } catch (RuntimeException e) {
    System.err.println("Caught RuntimeException: " +  e.getMessage());
    Yes, you can do that if you want to handle all of them the same.
    However, if you want to handle different exceptions differently, you'd catch those specific exceptions, rather than the parent exception type. This is a separate issue from whether you have one big try or lots of little trys.
    NOTE HOWEVER THAT YOU SHOULD NOT CATCH RuntimeException OR ITS DESCENDANTS. RuntimeException indicates an error in your code. Catching it is usually pointless, because you can't recover from it, and trying to continue on will probably lead to corrupt results at best.

  • [svn:fx-3.x] 10953: Get rid of a try/ catch block that was generating a lot of noise on the heap.

    Revision: 10953
    Author:   [email protected]
    Date:     2009-10-09 10:50:37 -0700 (Fri, 09 Oct 2009)
    Log Message:
    Get rid of a try/catch block that was generating a lot of noise on the heap.
    QE Notes: None
    Doc Notes: None
    Bugs: SDK-23563
    Reviewer: Ryan
    API Change: no
    Is noteworthy for integration: No
    tests: checkintests mustella/Managers/DragManager
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-23563
    Modified Paths:
        flex/sdk/branches/3.x/frameworks/projects/framework/src/mx/managers/dragClasses/DragProxy .as

    Revision: 10953
    Author:   [email protected]
    Date:     2009-10-09 10:50:37 -0700 (Fri, 09 Oct 2009)
    Log Message:
    Get rid of a try/catch block that was generating a lot of noise on the heap.
    QE Notes: None
    Doc Notes: None
    Bugs: SDK-23563
    Reviewer: Ryan
    API Change: no
    Is noteworthy for integration: No
    tests: checkintests mustella/Managers/DragManager
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-23563
    Modified Paths:
        flex/sdk/branches/3.x/frameworks/projects/framework/src/mx/managers/dragClasses/DragProxy .as

  • Nested try-catch blocks

    Hello All,
    If I have 2 nested try-catch blocks see below
    try{
        //Some code
        try{
            //Code that throws an IOException
        }catch(NumberFormatException nfe){
            //Handle the NFE
    }catch(Exception e){
        //Handle the Exception
    }Now what happens if in the inner try-catch an IOException is thrown? Will it be ignored, or will it get thrown out to the outer one and be caught by that catch?
    Thanks,
    Matt

    Thanks, should have just done this from the start, but here is the result...
    The following code
    public class Main {
         public void execute(){
              try{
                  try{
                       for(int i=0;i<100;i++){
                            System.out.println(i);
                            if(i==5){
                                 throw new java.io.IOException();
                  }catch(NumberFormatException nfe){
                     System.out.println("caught in inner block");
              }catch(Exception e){
                  //Handle the Exception
                 System.out.println("caught in outer block");
         public static void main(String[] args) {
              Main m = new Main();
              m.execute();
    }GENERATES:
    0
    1
    2
    3
    4
    caught in outer block
    Thanks,
    Matt

  • Try-catch blocks.  How do you get variables out?

    Hey guys,
    I have several try-catch blocks around potential NumberFormatException's. Well the variables and values given inside the try-catch block can not be used outisde, so how do i get them out or use them outside this block.
    Is there a way to kind of pass it out, or to take the variable outside the try-catch block?
    Gary.

    Declare the variable before the try block:
    public void foo(String number) {
    int i; // Unknown
    try {
    i = Integer.parseInt(number);
    } catch( NumberFormatException e ) {
    e.printStackTrace();
    System.out.println(i);
    variable i might not have been initialized
                   System.out.println(i);
                                      ^
    Or declare the method as throwing the exception so
    that you don't have to handle it directly
    public void foo(String number)
    throws NumberFormatException
    i = Integer.parseInt(number);
    System.out.println(i);
    }Not the best example, in this case. But it works for some things.
    Or make use of the variable within the try block so
    that you limit its scope to the degree possible
    public void foo(String number) {
    try {
    i = Integer.parseInt(number);
    System.out.println(i);
    } catch( NumberFormatException e ) {
    e.printStackTraceException();
    }Definitely missed declaring i, but I like this one best ;~)
    Each has its benefits. Depends what sort of method
    you're writing - if failure of the try block causes
    the whole method to fail, don't try to handle the
    exception locally, put the throws in the signature. ~Cheers

  • Help with reducing try catch blocks

    Hi,
    I have an object of a class having about 100 get methods. I have about 300 such objects. I want to get all the parameters from all the 100 get methods for all the objects, and for each failed get methods, an exception occurs,
    Now I can loop from - to no of objects but inside I have to declare 100 try catch methods for each get methods.
    for(i=0;i< 300;i++) {
    try {
       a.getname;
    catch { --- }
    try{
    a[i].getno ;
    catch { -- }
    100 such a[i].getXYZ methods
    any alternative. wanted to avoid all the try catch statements
    Please suggest
    thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    tarkesh wrote:
    Its actually a serialized object, which I am trying to extract parameters from. So I actually need to know exactly which get method is failing for which object, as the objects can be in error when they get transported over the network.If it was me I would generate the code so the actual mechanism becomes moot.
    But you can use something like the following (generated or not.)
           String attrName="<Unknown>"
           try
                 attrName = "attr1";
                 attr1=instance.attr1;
                 attrName = "attr2";
                 attr2 = instance.attr2;
           catch(Exception e)
                 // attrName has correct name here.
           }

  • Escaping Boolean & Try/Catch blocks

    Hi everyone-
    You all have been so great. I finally got my double/int and all working on my calculator. Now, I have one more question that I cannot figure out. My booleans to escape when form is not completed correctly are not working. That is, it will output error, but then still attempt the rest, giving printouts/general exception. I tried using another boolean, but not working. Here is the applet:
    www.quiltpox.com/HSTCalc.html
    and code: www.quiltpox.com/HSTCalc.java
       public void actionPerformed(ActionEvent evt) { //1
                     //declarations
             try{
              //reset all fields to null so user can start over
              if(source == button1)
                   text1.setText("");     
                   text2.setText("");
                   text3.setText("");
              if(source == button2)
                   //check that all fields have been completed
                   if(t1.length() == 0 || t2.length() == 0 || t3.length() == 0)
                            output.append("\nPlease complete the required fields and try again.");
                            verify = false;
                   //parse string into integer data and verify
                   if(verify)
                   //parsing
                   if(size == 0 || numOfSquares == 0 || WOF == 0)
                        output.append("\nYou have entered a null value for Square Size, " +
                             "\nQuantity of HSTs, and/or Fabric Width. Please try again. ");
                        verify = false;
                        proceed = false;
                   if(proceed)
                        all codes/printouts/methods
                   }     //end of if proceed
                   }     //end of verify
              }     //end of if
               }     //end of try
            catch (Exception e ) {
                    output.append("General Exception");
              finally {
                    textArea1.setText(output.toString());
       }     //end of action performed(i hope i quoted that right)
    Any ideas on how to resolve this? I know I could use a switch in a standard java, but not sure if that works with applet/try-catch.
    Thanks again,
    Kimberly

    You need to use "else" clauses here.if(t1.length() == 0 || t2.length() == 0 || t3.length() == 0)
      output.append("\nPlease complete the required fields and try again.");
    } else {
      if(size == 0 || numOfSquares == 0 || WOF == 0)
        output.append("\nYou have entered a null value for Square Size, " +
        "\nQuantity of HSTs, and/or Fabric Width. Please try again. ");
      } else {
        // all codes/printouts/methods

  • Handling the ASSIGN_TYPE_CONFLICT in a try catch block

    Hi,
    Post WAS 610 all system exceptions are handled by exception classes, I could not find the exception class for the runtime exception ASSIGN_TYPE_CONFLICT, if any body is in knowledge of the same or knows of a better way to handle the runtime exception kindly let me know.
    Thanks in advance.
    Aniruddha Gargya

    Hi Raja,
    I have already tried all teh exceptions listed for type conversion and assign. The help document also suggested that teh exception class name for a runtime exception will appear in the system trace.
    The issue still remains where it was, When i get this execption from a web page the same is not being caught.
    Thanks and Regards,
    Aniruddha Gargya

  • Return statement inside a catch block???

    If you put a return statement inside of a catch block, what statements will be executed next? I.e., what happens to the flow of control?

    If you put a return statement inside of a catchblock, what statements will be executed next? I.e.,
    what
    happens to the flow of control?If you write a short testing sample, compile it and
    run it, what do you get as a result ?
    Eek! That actually involves effort! Are you kidding?Kidding ? Me ?
    I'd better waste my time writing programs for lazy OPs !
    ;)

  • Return statement inside try block

    what is wrong if i write code like as below...please explain me since i am new to java
    class sample{
    public String method(){
    try{
    String str="abc";
    return abc;
    catch(Exception e){}
    }

    veldhanas wrote:
    return abc;In your code there is no varible declared as abc. It is a value assigned in str.
    Suppose if the code in try statement throws exception the return statement is skipped and the
    associated catch block will get executed. So your catch block must return a result of type String.... or throw another (or the same) exception.
    In this case, since there's no way the code in the given "try" block can throw an exception, it would have been better to not even have a try/catch block in the first place.
    And almost never just swallow exceptions like that (an empty catch block). There are only a few cases where it's ok to swallow them (such as in finally blocks where you're cleaning up resources which may throw exceptions while cleaning up, and you want to continue cleaning up and ignore those kinds of exceptions).

Maybe you are looking for

  • How to make the images show up on a linked file in Muse?

    I am wondering how to get my images to show up on the linked files in Muse.  Basically, in Muse, I have a page that links to other pages I designed in Dreamweaver.  I put the images in the image folder and when I upload the site, the page links to th

  • Having Problem with JSP In Netscape!HELP!!!

    HI to all! I�m having problem with the jsp that i have :( If i use the Internet explorer it works but at Netscape... it doesn�t work :( The value of "PTE" is null... I need help !!!Please! I think the HTML IS NOT HELPING ... the code is : <html> <hea

  • Materialized view issue ORA-12052

    Hi All, I'm currently trying to create a MV using Fast refresh method. and I'm getting the following error: ORA-12052: cannot fast refresh materialized view string.string Cause: Either ROWIDs of certain tables were missing in the definition or the in

  • Why do we have to pay to upgrade? WTH

    Not only have the iTunes song prices went up but now we have to pay to upgrade? Maybe I've been out of the loop...But i'd really like to know why are users having to pay for it. And at $9.99?

  • OS Migration from HP Unix to AIX

    Hello Everyone, I am in the process of building a Sandbox system for my OS migration and upgrade. My source system is on R3 4.7 Ext. Set 2 and Oracle as 9.2.0.5 and OS as HP Unix 11.21. My target is to migrate this system to AIX 6.1. Can someone plea