Exception declaration for methods in a Controller

Hi all enthusiasts of WD,
me again :-). I just noticed that one cannot declare exceptions thrown by a public method in a controller. Is it on purpose to shut down exception handling?
Maybe it makes sense to forbid this for the component interface controller, since the interface controller is accessible outside the component, it's not a good idea to ask other components to handle the exceptions specific to one component (after all, a component should be a self-contained unit); but for other controllers like component controller, it's convenient and safe to allow exception declaration --- it can only be accessed inside the component anyway.
Will this be supported in the future? Thanks.
Best regards,
Ge

Ge,
You misinterpreted my answer a bit.
1. Create own subclass of RuntimeException so you may distinguish your exceptions and standard ones like NullPointerException, ArrayIndexOutOfBoundsException:
public class GeRuntimeException extends RuntimeException {
  public GeRuntimeException(final String message) { super(message); }
  public GeRuntimeException(final Throwable cause) { super(cause); }
  public GeRuntimeException(final String message, final Throwable cause) { super(message, cause); }
2. Next create concrete sublcasses of your superclass:
public class GeSecurityException extends GeRuntimeException {
public class GeDatabaseException extends GeRuntimeException {
  public GeDatabaseException(final java.sql.Exception cause) { super(cause); }
3. Typical code pattern that throws your exception:
final PreparedStatement pstmt = ...;
try {
  pstmt.setInt(1, 0);
  pstmt.setString(2, "String param");
  pstmt.executeUpdate();
} catch (final SQLException ex) {
  throw new GeDatabaseException(ex);
4. Typical code pattern that handle exception:
try {
  wdThis.wdGetOtherController().makeDatabaseCall();
} catch (final GeDatabaseException ex) {
  wdComponentAPI.getMessageManager().reportException(
    new WDNonFatalException( ex.getCause() ), false
  return;
} catch (final GeRuntimeException ex) {
  wdComponentAPI.getMessageManager().reportError("Unexpected failure");
  return;
/* Some other code if no exception */
Notice that code above does not catch generic RuntimeException, only your sublcasses.
Valery Silaev
SaM Solutions
http://www.sam-solutions.net

Similar Messages

  • How to catch exception for class CL_HR_RE512W for method CHECK_CUMULATION

    Hi,
    How do I catch an exception when using method CHECK_CUMULATION in class CL_HR_RE512W.
    This method calls an instance method READ which raises NO_ENTRY if a wage type is missing on T512W.
    There is no obvious catch class to use?
    My code:
    data: r_512w type ref to cl_hr_re512w.
    start-of-selection.
    create OBJECT r_512w.
    call method r_512w->check_cumulation
    exporting
        p_molga  = molga
        p_lgart  = lgart
        p_cumul  = cumul
        p_date   = date
    receiving
          p_has_cumulation = p_flg.
    If lgart = '9999', for example, then we get an error message:
    'No entry in table T512W for key 08 9999 25.08.2009'

    Hi Gemini Twin,
    Check this link:
    https://wiki.sdn.sap.com/wiki/display/Snippets/ABAP+Objects+-+Defining+a+Class-based+exceptions
    Hope this information is help to you.
    Regards,
    José

  • Exception handling for ProjectService methods in a new 2006 DI API

    Normally for other objects the Add() method returns error code and calling the GetLastError you get the description.
    AddProject(Project) method of ProjectService returns ProjectParams object.
    So the question is where to get the error code or what is the correct exception handling for that new methods in 2006 SDK.
    Thanks for any help.
    Tomas

    Hi all,
    I have a sceranio :
    I created the text field, text box, com bobox .etc, on new form or exist form.
    When I want to bind data into UDO, i use "DataBind.setBound"
    ex:"oEdit.DataBind.SetBound(True, "@SM_OMOR", "U_Room")"
    Can i bind the data to exist table on B1?
    ex: oEdit.DataBind.setBound(True, "OHEM", "firstName")
    Plz guid !
    Rgds !

  • 2007A: Exception handling for new ProjectService methods

    Normally for other objects the Add() method returns error code and calling the GetLastError you get the description.
    AddProject(Project) method of ProjectService returns ProjectParams object.
    So the question is where to get the error code or what is the correct exception handling for that new methods in 2006 SDK.
    Thanks for any help.
    Tomas

    Hi Thomas,
    For DI API services there is no return code as for the basic objects methods like Add, Update,...
    The only way is then to put try/catch blocks in your code and identify the error message with the Exception.Message property (same mechanism as we have for the UI API). No way to filter them by return code.
    Regards
    Trinidad.

  • Exception '1250' is not defined for method 'CREATE' object type 'MESSAGE'

    Dear experts,
    I set up the document distribution (SWU3, backgroundjob SMTP, activated the workflows, flagged the linkages, etc). Now, I have still a error:
    Exception '1250' is not defined for method 'CREATE' object type 'MESSAGE'
    Does anyone know what the cause of exception 1250 could be?
    Thanks in advance and kind regards,
    Samuel

    hi,
    SAP ITS is SAP Internet Transaction Server which provides connection between SAP ERP system and html client.
    Check with bassis, i think TCP/IP or work station application not configured yet. i guess?
    Benakaraja
    ??P

  • Exception '1003' is not defined for method 'SENDTASKDESCRIPTION' object type 'SELFITEM'

    Hi All,
    Please help me in this. I am trying to send a mail when user rejected the item in his inbox. I am getting error like
    Exception '1003' is not defined for method 'SENDTASKDESCRIPTION' object type 'SELFITEM'. I tried so  many ways like no attachments,send express ,siganture,encryption all disabled but still the same error from user outbox who ever rejects it.
    Regards,
    Madhu.

    Hi Madhu,
    This exception is raised means you have checked the Signature check-box  and encrypt check box.
    Now you have unchecked that the issue should be solved , but if it is still giving the same exception synchronize your run time buffer using the t-code SWU_OBUF .
    Let me know if the issue is still there.
    Regards
    Bikas

  • Forte C++:error: Multiple Declaration for std::exception

    Hi,
    I am trying to compile code written in C++ 4.2/solrais 2.6 with Forte 6 C++ compiler on Solaris 7. Getting the following error.
    /opt/SUNWspro/WS6/include/CC/exception.h Line 17: Multiple Declaration for std::exception.
    Tried running only the preprocessor using -E option and noticed from the output that both "exception" and "exception.h" contents included.
    Any help!

    I got this same error and was able to fix it by eliminating
    #include <math.h> in my code.
    As it turned out this #include was not needed.
    It then compiled in standard mode.
    Hope this helps.

  • Exception on overridden methods

    hi ,
    we know that An overriding method in a subclass may only throw exceptions declared in the parent class or children of the exceptions declared in the parent class. but in a program it is written
    class base {
    public static void method1() {
    public class child extends base
    public static void method1() throws ArrayIndexOutOfBoundsException
    its being compiled ok.
    but when me writting
    class base {
    public static void method1() {
    public class child extends base
    public static void method1() throws Exception
    its giving compilation error.
    please explain this....

    hi ,
    we know that An overriding method in a subclass may
    only throw exceptions declared in the parent class or
    children of the exceptions declared in the parent
    class. but in a program it is written
    This only applies to checked exceptions. It does not apply to unchecked exceptions like ArrayIndexOutOfBounds. Methods that throw unchecked exceptions do not need to have a throws cause, although including a throws cause for an unchecked exception is allowed.
    If you change your code so the method throws a checked exception, you will get the error.
    http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html#67305

  • WARNING: Problem validating implementation class. Exception declaration mis

    I have created sample class using JDevStudio10.1.3
    Added method getX() throws Ex (Ex implements Exception)
    Select class and generated J2EE 1.4 RPC webservices
    Got the warning :
    Generating WSDL and mapping file
    WARNING: Problem validating implementation class. Exception declaration mismatch between Implementation: mypackage.Class3 and Interface: mypackage.MyWebService3. Impl class Method: X declares exceptions not declared by the interface (mypackage.Exp)
    Now When I generated client proxy from the wsdl generated, Ex class is not getting generated.
    Can some one help me please.
    Thanks in advance

    If you are using Ex in the implemetation class, make sure that you also include the same in the interface (or SEI).
    If the implementation looks something like:
    public void doSomething() throws Ex {
    System.out.println("Is there something to do, now ?");
    then the SEI should be:
    public void doSomething() throws Ex, RemoteException;
    If your have ommited Ex, then you will have the warning you are seing, and there wont be any artifact generated for Ex in the WSDL.
    Because the Ex exception was not mapped to any WSDL artifact, there is no way you will see the Ex exception generated on the client side (or proxy).
    I have been able to reproduce your error message, so you should be all good.
    WARNING: Problem validating implementation class. Exception declaration mismatch between Implementation: bugyyy.MyServiceImpl and Interface: bugyyy.MyWebService. Impl class Method: doSomething declares exceptions not declared by the interface (bugyyy.Ex)
    Hope this helps,
    Eric

  • Exceptions declared as inner class.

    1) Is it a good idea to declare
    exceptions as an inner class, of a root class, from which it is actually
    thrown.?
    2. So if there are 6 exceptions which are thrown
    from the methods of the root class, I will declare 6 inner exception
    classes in that root class.
    3. Instead of a root class if I have an interface
    is it ok to declare these exception classes in the interface?
    4. What do you think about this logic?
    There are more Exception classes than our actual classes,
    so it looks bad, why don't we put all the exception classes
    as inner class in one rootException class?

    >
    If the API user does not catch the exception and
    handle it properly then we cannot do much. That isn't what I asked.
    I asked if the application code, not the test code, explicitly has a catch block for each exception.
    For example if you have the following exceptions.
                class BaseException
                class Exception1 extends BaseException
                class Exception2 extends BaseException
    Then that means you have the following code.
                  catch(Exception1 e)
                     // Do something with the exception BESIDES logging it
                  catch(Exception2 e)
                     // Do something with the exception BESIDES logging it
      Notice in the above that the catch block MUST do something besides just log the exception. Logging doesn't count.
    So does your code do this?

  • Declaring static methods.

    I have some questions about declaring a method as static. If I first write a paragraph about my understanding so far, followed by a code snippet hopefully somebody can help me out.
    It is my understanding (limited) that only one class is loaded by the classloader. When creating an object, all its parameters are stored, but each object does not have its own copy of the methods its class defines, each method. If a method is declared as static then you do not have to create an instance of this class to call this method.
    Code
    /** Get table of codes.
          * @return <code>Hashtable</code> populated with clinical code values.
        public Hashtable getCodeHashtable(HttpServletRequest request) {
            Hashtable htResults = new Hashtable();
            try {
                SpParameter[] spOut = {
                    new SpParameter(OracleTypes.CURSOR, 0)//po_cur_data
                 HOUtils utils = new HOUtils();
                UtilDBquery db = utils.getUtilDBquery(request);
                htResults = db.runGeneralStoredProcedureThrowsExceptions(null, spOut, SP_CodeList, null, true, true);
            } catch (Exception e){
                 e.printStackTrace();
            return htResults;
    Questions
    1) If each object does not carry around its own copy of the methods associated with its class, how does the jvm know which object is calling a method?
    2) In the above code snippet, if I were to make the method static would this have implications if 2 people were to browse to the same page on the app server and run this method at the same time?
    Thanks for any replies.

    1) If each object does not carry around its own copy of the methods
    associated with its class, how does the jvm know which object is
    calling a method?Each object stores one single pointer to its class description. The class
    description contains all the methods (also the static ones). This is a bit
    of a simplification but basically that's all there is to it. When you call
    a method, the address of the method is looked up in that class description
    and it's invoked. For non static methods there's a hidden parameter,
    called 'this' so the method always 'knows' which object it (the method)
    is invoked on. For static methods that hidden parameter simply isn't
    present.
    2) In the above code snippet, if I were to make the method static
    would this have implications if 2 people were to browse to the same
    page on the app server and run this method at the same time?Who knows? This all depends whether or not the method (static or not)
    is reentrant, i.e. does the method have side effects? Does the method
    needs to be synchronized?
    kind regards,
    Jos

  • Purpose of declaring the method or class or static and as instance

    what is the purpose of declaring a method in a class or the class itself as static.
    Does it mean we cannot create a copy of that class or method if we declare it as static.
    if so then why do they dont want that class to be created as a copy ?
    Why do they want to declare a class as static
    please provide some conceptual undersatnding regarding the static and instance class with one example

    Static methods are often used for the implementation of utility methods. Please have a look at the class CL_ABAP_CHAR_UTILITIES for example.
    You use the methods of this class in the same way as you would use a function in ABAP (like
    LINES( itab )
    ). You use it in a static way because the functionality is always the same no matter in what context you are calling the function.
    The purpose of instance methods is that their logic is in some way related to an attribute of the object instance that you use to call it.
    For example, you create an instance of object PO (a purchase order) called MY_PO. Then the method
    MY_PO->ADD_POSITION
    would add a position to a concrete PO that has a unique number etc. But if the object has a static method DELETE_POSITION then it just deletes the current position of a PO, regardless on which concrete PO you are acting at the moment.
    I hope this clarifies it for you.
    Regards,
    Mark

  • Error on /SafeMode: error while trying to run project uncaught exception thrown by method called

    i try run VS 2012 with /SafeMode. I create new empty Winform. When I start debug, I got:
    "error while trying to run project uncaught exception thrown by method called through reflection"

    Hi Matanya Zac,
    Did you restart your machine? How about installing the VS2012 update 4?
    >>error while trying to run project uncaught exception thrown by method
    Did you install the VS update in your VS IDE? I met this issue before which was related to the VS update:
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/5ead8ee9-ea09-4060-88b0-ee2e2044ff82/error-while-trying-to-run-a-project-uncaught-exception-thrown-by-method-called-through-reflection?forum=vsdebug
    If still no help, I suggest you repair your VS, and then restart your machine, test the result.
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Exception handling for all the insert statements in the proc

    CREATE PROCEDURE TEST (
    @IncrStartDate DATE
    ,@IncrEndDate DATE
    ,@SourceRowCount INT OUTPUT
    ,@TargetRowCount INT OUTPUT
    ,@ErrorNumber INT OUTPUT
    ,@ErrorMessage VARCHAR(4000) OUTPUT
    ,@InsertCase INT --INSERT CASE INPUT
    WITH
    EXEC AS CALLER AS
    BEGIN --Main Begin
    SET NOCOUNT ON
    BEGIN TRY
    DECLARE @SuccessNumber INT = 0
    ,@SuccessMessage VARCHAR(100) = 'SUCCESS'
    ,@BenchMarkLoadFlag CHAR(1)
    ,@BenchmarkFlow INT
    ,@MonthYearStart DATE
    ,@MonthYearEnd DATE
    ,@StartDate DATE
    ,@EndDate DATE
    /* Setting the default values of output parameters to 0.*/
    SET @SourceRowCount = 0
    SET @TargetRowCount = 0
    /*Setting the Start and end date for looping */
    SET @MonthYearStart = @IncrStartDate;
    SET @MonthYearEnd = @IncrEndDate;
    /* Setting the @InsertCase will ensure case wise insertion as this sp will load data in different tables
    @InsertCase =0 means data will be inserted in the target TAB1
    @InsertCase =1 means data will be inserted in the target TAB2
    @InsertCase =2 means data will be inserted in the target TAB3
    @InsertCase =3 means data will be inserted in the target TAB4
    @InsertCase =4 means data will be inserted in the target TAB5
    @InsertCase =5 means data will be inserted in the target TAB6
    if @InsertCase =0
    WHILE (@MonthYearStart <= @MonthYearEnd)
    BEGIN
    SET @StartDate = @MonthYearStart;
    SET @EndDate = @MonthYearEnd;
    /* Delete from target where date range given from input parameter*/
    DELETE FROM TAB1
    WHERE [MONTH] BETWEEN MONTH(@StartDate) AND MONTH(@EndDate)
    AND [YEAR] BETWEEN year(@StartDate) and year(@EndDate)
    /*Insert data in target-TAB1 */
    BEGIN TRANSACTION
    INSERT INTO TAB1
    A,B,C
    SELECT
    A,BC
    FROM XYZ
    COMMIT TRANSACTION
    SET @MonthYearStart = DATEADD(MONTH, 1, @MonthYearStart)
    SELECT @TargetRowCount = @TargetRowCount + @@ROWCOUNT;
    END -- End of whileloop
    END TRY
    BEGIN CATCH
    IF @@TRANCOUNT>0
    ROLLBACK TRANSACTION
    SELECT @ErrorNumber = ERROR_NUMBER() ,@ErrorMessage = ERROR_MESSAGE();
    END CATCH
    END--End of Main Begin
    I have the above proc inserting data based on parameters  where in @InsertCase  is used for case wise execution.
     I have written the whole proc with exception handling using try catch block.
    I have just added one insert statement here for 1 case  now I need to add further insert  cases
    INSERT INTO TAB4
                    A,B,C
    SELECT
                                    A,BC
    FROM XYZ
    INSERT INTO TAB3
                    A,B,C
    SELECT
                                    A,BC
    FROM XYZ
    INSERT INTO TAB2
                    A,B,C
    SELECT
                                    A,BC
    FROM XYZ
    I will be using following to insert further insert statements 
    if @InsertCase =1 
    I just needed to know where will be my next insert statement should be fitting int his code so that i cover exception handling for all the code
    Mudassar

    Hi Erland & Mudassar, I have attempted to recreate Mudassar's original problem..here is my TABLE script;
    USE [MSDNTSQL]
    GO
    /****** Object: Table [dbo].[TAB1] Script Date: 2/5/2014 7:47:48 AM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[TAB1](
    [COL1] [nvarchar](1) NULL,
    [COL2] [nvarchar](1) NULL,
    [COL3] [nvarchar](1) NULL,
    [START_MONTH] [int] NULL,
    [END_MONTH] [int] NULL,
    [START_YEAR] [int] NULL,
    [END_YEAR] [int] NULL
    ) ON [PRIMARY]
    GO
    Then here is a CREATE script for the SPROC..;
    USE [MSDNTSQL]
    GO
    /****** Object: StoredProcedure [dbo].[TryCatchTransactions1] Script Date: 2/5/2014 7:51:33 AM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE [dbo].[TryCatchTransactions1] (
    @IncrStartDate DATE
    ,@IncrEndDate DATE
    ,@SourceRowCount INT OUTPUT
    ,@TargetRowCount INT OUTPUT
    ,@ErrorNumber INT OUTPUT
    ,@ErrorMessage VARCHAR(4000) OUTPUT
    ,@InsertCase INT --INSERT CASE INPUT
    WITH
    EXEC AS CALLER AS
    BEGIN --Main Begin
    SET NOCOUNT ON
    BEGIN TRY
    DECLARE @SuccessNumber INT = 0
    ,@SuccessMessage VARCHAR(100) = 'SUCCESS'
    ,@BenchMarkLoadFlag CHAR(1)
    ,@BenchmarkFlow INT
    ,@MonthYearStart DATE
    ,@MonthYearEnd DATE
    ,@StartDate DATE
    ,@EndDate DATE
    /* Setting the default values of output parameters to 0.*/
    SET @SourceRowCount = 0
    SET @TargetRowCount = 0
    /*Setting the Start and end date for looping */
    SET @MonthYearStart = @IncrStartDate;
    SET @MonthYearEnd = @IncrEndDate;
    /* Setting the @InsertCase will ensure case wise insertion as this sp will load data in different tables
    @InsertCase =0 means data will be inserted in the target TAB1
    @InsertCase =1 means data will be inserted in the target TAB2
    @InsertCase =2 means data will be inserted in the target TAB3
    @InsertCase =3 means data will be inserted in the target TAB4
    @InsertCase =4 means data will be inserted in the target TAB5
    @InsertCase =5 means data will be inserted in the target TAB6
    IF @InsertCase =0
    WHILE (@MonthYearStart <= @MonthYearEnd)
    BEGIN
    SET @StartDate = @MonthYearStart;
    SET @EndDate = @MonthYearEnd;
    /* Delete from target where date range given from input parameter*/
    DELETE FROM TAB1
    WHERE START_MONTH BETWEEN MONTH(@StartDate) AND MONTH(@EndDate)
    AND START_YEAR BETWEEN year(@StartDate) and YEAR(@EndDate)
    /*Insert data in target-TAB1 */
    BEGIN TRANSACTION
    INSERT INTO TAB1 (COL1,COL2,COL3)
    VALUES ('Z','X','Y')
    SELECT COL1, COL2, COL3
    FROM TAB1
    COMMIT TRANSACTION
    SET @MonthYearStart = DATEADD(MONTH, 1, @MonthYearStart)
    SELECT @TargetRowCount = @TargetRowCount + @@ROWCOUNT;
    END -- End of whileloop
    END TRY
    BEGIN CATCH
    IF @@TRANCOUNT > 0
    ROLLBACK TRANSACTION
    SELECT @ErrorNumber = ERROR_NUMBER() ,@ErrorMessage = ERROR_MESSAGE();
    END CATCH
    PRINT @SUCCESSMESSAGE
    END--End of Main Begin
    GO
    I am just trying to help --danny rosales
    UML, then code

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

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

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

Maybe you are looking for