How to use user defined exception class

Hi all
I just need som help with creating a user defined exception class.
Im writing a small/simple text editor.
My exception class looks like this:
public class myExcp extends Throwable
     private String message;
     public myExcep(String message)
          this.message = message;
     public void display()
I would like to use it when a user tries to open a exe-file instead of a txt file.
Here is some code from the editor:
if (e.getSource() == open)
if (fc.showOpenDialog(null)== JFileChooser.APPROVE_OPTION)
So, should I use exception here or at the readFile method?
private void readFile(String fileName)
String tmp = fileName.substring(fileName.length() -4, fileName.length());
if (!tmp.equals(".exe"))
FileReader r = new FileReader(fileName);, null);
currentFile = fileName;
changed = false;
catch (IOException e)
JOptionPane.showMessageDialog (this, "Cannot find the file " + fileName);
Where and how do I use my exception class.
Do I need to create an instance? Where?
Should the exception class extend Exception instead?
Thank you in advance /

Extend Exception, not Throwable. It's a checked exception that way.
Follow the Sun coding standards and make that exception class name start with a capital letter.
When you extend Exception, override all four ctors.
What's that display method you added? Isn't getMessage() good enough?
You need to create a new instance just before you throw the exception, of course.
Sounds like a terrible design, by the way. Exceptions shouldn't be used like "go to" for app logic. They should signal unrecoverable conditions. You can easily recover from the situation you've described simply by displaying a pop-up that tells the user to open only text-readable file types. I think that's a better solution.

Similar Messages

  • How to use user-defined packages in JAX-RPC web service

    I am trying to use Object of my class located in my package in jax-rpc webservice,the code is
    package supercomputer;
    import Hello.*;
    public class SuperImpl implements SuperIF
    public String sendParam(String data)
    Temp ob=new Temp();
    int i=ob.get1(10000);
    return data+"returned by supercomputer";
    Temp is located in Hello package,I have jar the Hello package as Hello.jar and has set its classpath in targets.xml of Ant tool.
    The code compiles well and service is deployed successfully,but when i try to call the service from the client its gives me following error.
    [echo] Running the supercomputer.SuperClient program....
    [java] java.rmi.ServerException: Missing port information
    [java] at com.sun.xml.rpc.client.StreamingSender._raiseFault(
    [java] at com.sun.xml.rpc.client.StreamingSender._send(
    [java] at supercomputer.SuperIF_Stub.sendParam(
    [java] at supercomputer.SuperClient.main(Unknown Source)
    I dont know if it deploys why it gives error on client side.
    Please tell how to use user-defined packages and class in jax-rpc service code ,i am not talking about passing user-defined parameters i am just talking about making objects of user defined classes in jax-rpc service.I think there is some problem in classpath.
    Please guide me in doing that.

    I don't know if your error is about a missing class from your custom package, ... what track did you followed to say that?
    To use your package in the implementation of you web service, you should only follow the rules of making a web application: put your package jar in your \lib directory inside WEB-INF/ or your package classes unjared in classes (also in WEB-INF/).
    As I already said, I have doubts that your error should be originated from a missing class from your package, but:
    -try to see the logs (errors?) when you deploy your web service that could give a hint about the problem.
    -try to see if you can access your endpoint through your browser to see if there is a online status
    -display your config/WSDL file, and the steps you did to build your web service.
    Pedro Salazar.

  • How to handle user defined exception from C#?

    I have some PL/SQL code that will throw a user defined exception if certain conditions are met. How do I handle user defined exceptions if this procedure/function is being called from C#? C# can handle a normal Oracle SQL error (e.g. ORA-XXXX) because they are defined in the proper class, but how do I get it to know about my user defined exception? Does anyone have any links to examples of doing this?

    Hi Gaff,
    Is there a particular problem you're having doing this? It works as normal for me...
    create or replace procedure throwsomething as
        class Program
            static void Main(string[] args)
                using (OracleConnection con = new OracleConnection())
                    con.ConnectionString = "user id=scott;password=tiger;data source=orcl";
                    using (OracleCommand cmd = new OracleCommand())
                        cmd.CommandText = "begin throwsomething;end;";
                        cmd.Connection = con;
                        catch (OracleException oe)
                            Console.WriteLine("caught " + oe.Message);
    caught ORA-20001: kaboom
    ORA-06512: at "SCOTT.THROWSOMETHING", line 3
    ORA-06512: at line 1

  • How to use user defined object with linked button

    Hi experts
    Can I use user defined table data with linked button. If yes then how. plz give me sample examples.

    If you have an UDO in your form, or any other, the FormDataLoad eventhandler should be used.
    Take care, it is not inside the eventhandler.
    for VB:
    Select SBO_APPLICATION in the classes, and select FormDataLoad event
    Private Sub SBO_Application_FormDataEvent(ByRef BusinessObjectInfo As SAPbouiCOM.BusinessObjectInfo, ByRef BubbleEvent As Boolean) Handles SBO_Application.FormDataEvent
    in C#
    Add a new eventhandler as
    // declaration
    SBO_Application.FormDataEvent += new SAPbouiCOM._IApplicationEvents_FormDataEventEventHandler(ref SBO_Application_FormDataEvent);
    // eventhandler:
    public void SBO_Application_FormDataEvent(ref SAPbouiCOM.BusinessObjectInfo BusinessObjectInfo, out bool BubbleEvent)

  • How to use user defined contact fields in the intelligent group builder

    In Apple Contacts it seems not being possible to build an intelligent contact group using an user defined, additional field. The builder seems to work exclusively with a system defined selection of the basic database fields. Please, tell me, that there is a way ...

    Please, can sombody out there help?

  • Pls. help - How to use user defined URL?

    The page users access currently for login is (only over the Intranet)- http://servername/pls/portal30/url/page/pagename
    I need users to be able to point to -
    and be taken to the above Login page.
    What needs to be setup (Apache/Portal)??
    I created a Virtual Hosts entry in the httpd.conf file -
    That did not help. What am I missing?

    Pls. refer Portal FAQ. Here is how it works
    Use the Apache Redirect directive in the <ORACLE_HOME>/Apache/Apache/conf/httpd.conf file. For example, if your site's full URL is, you can place the following directive in httpd.conf:
    Redirect /portalhome
    Then, if you try:
    you will be redirected to the original URL. This technique will also work with any valid path that is appended to the URL. For example:
    will redirect the user to the Online Help content area.

  • How to use user defined function in select query using Toplink

    Hi Friends
    I am little bit of new in Toplink stuff... so please help me...
    I have to database functions 1. encrypt and 2. decrypt.
    I want to exceute the following sql query using toplink
    select port, database, user_name, decrypt(encrypt('String which is to be encrypt ','password'),'password') from CONFIGURATION
    can anyone tell me , how to write code in toplink which will give the about sql output.
    thanks .....

    The "Specifying a Custom SQL String in a DatabaseQuery" section in the TopLink Developer's Guide may help...

  • How to use user defined contact fields in Pages 4.3?

    I would like to use new fields definded in Contacts (Vers. 7.1) in Pages (Vers. 4.3) for personalizing documents on my iMac under Mountain Lion. Is this possible, and how? Thank you.

    Yes, here are four of them:
    #1: shows the new field "foo" in the template
    #2: shows "foo" in the list of names
    #3: shows "foo" while editing a new card
    #4 shows the absence of "foo" in the available names while trying to put the field "foo" in a pages document.

  • How to use User defined Function in Update statement

    Hi All,
    I have written below update statement to update column based on value return by function. but it is not working. Could any one help me on this. This function will return only one value for each project.
    thanks in advance.
    SET Months_In_Stage_Cnt = select Months_In_Stage_Cnt_ret(o.project_id) from dual;

    CREATE FUNCTION fn_emp_ename (p_empno IN emp.empno%TYPE)
       v_ename   emp.ename%TYPE;
       SELECT ename
         INTO v_ename
         FROM emp
        WHERE empno = p_empno;
       RETURN v_ename;
          RETURN NULL;
          RETURN NULL;
    END fn_emp_ename;
    SQL> select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
    14 rows selected.
    SQL>  select fn_emp_ename (empno) as  emp_name from emp;
    14 rows selected.
    SQL> update emp
      2  set ename= fn_emp_ename (7936)
      3  where empno=7934;
    1 row updated.
    SQL> commit;
    Commit complete.
    SQL>  select * from emp where empno=7934;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTN
          7934            CLERK           7782 23-JAN-82       1300                    1
    SQL> i hope this helps .........
    P Prakash
    Edited by: prakash on Nov 17, 2011 11:52 PM

  • "user defined exception" in a stored procedure and APEX

    I would like to use user defined exception in a stored procedure or trigger in a APEX application.
    Does anybody know how to do it ? or know where can I find a good reference ?

    raise_application_error(-20001, 'error message');

  • About semantic indexing using user defined ontology

    hi zhe,
    according to the dev. guide, you can do semantic index on a document using user defined ontology. however, multiword class names, individual names and property names defined in the ontology are usually concatenated and cannot have space. if I have a multiword concept such as "" rather than " Past Neurological Deficit" in the ontology and a loaded document in the table also contains the concept "Diagnosed Past Neurological Deficit", so how is the extractor able to identify the concept in the document? do I need to describe the concept in the ontology using rdfs:lable like this "<rdfs:label xml:lang="en">Diagnosed Past Neurological Deficit</rdfs:label>" so that extractor can identify the concept in the document? I am not clear how to use user defined ontology to semantically index documents. thanks a lot in advance.

    Hi Hong,
    The semantic indexing feature is itself a framework. There is no native NLP engine bundled with it.
    There are NLP engines like Open Calais, GATE, and Lymba that can work with this framework. Some engines
    can take an ontology and map entities (events, individuals, relationships etc.) embedded in the text to definitions in the ontology. You can also perform the mapping yourself. For example, you can take out the rdfs:label (or comment, or some other descriptive parts) of URIs, build an Oracle Text index, perform a fuzzy text match for a given piece of phrase, and select the URI that gives the best matching score.
    Hope it helps,
    Zhe Wu

  • Using user defined variables in SAP BPC 7.0 NW

    I am using BPC 7.0 SP2 NW version. I want to do some calculatioins and/or comparision in the script logic by using user defined variables.
    For Ex: I want to assign the property TIMEID of TIME dimension to a variable and then use this variable in my IIF statement.
    I have tried a lot but not getting any solution.
    Can anyone guide me in how to use user defined variables in Script Logic.
    Your valuable reply is appreciated.
    Thanks & Regards
    Manoj Damle

    Thanks for the valuable reply.
    But i want to define variables in the Script Logic and not in the Data Manager.
    The scenario is like this:
    I want to check the value of the DUMMYACC1 member of GL_ACCOUNT dimension with a constant and depending on the condition i want to update a user defined variable. This variable will further be used in the *SELECTCASE statement for decision making.
    The Code is as follows:
        *FOR %CV_TIM% = 2009.MAY,2009.JUN
            #CUR_MTH = IIF(([GL_ACCOUNT].[%GL_ACC%],[TIME][%CV_TIM%]) = 1.,1,NULL)
    *CASE 1
    The errors which system gives is:
    1. Duplicate formula found
    2. Invalid MDX statement
    3. #CUR_MTH & #CURRENTMTH is not a valid member
    Please give your valuable suggestion.
    Thanks and Regards
    Manoj Damle

  • Why User Define Exception range from -20,000 to -20,999

    Can any one told me why we are using user define exception as ( -) 'Negative' range from -20,000 to -20,999. Why not Positive.

    Oracle error codes are negatives.
    Ott Karesz

  • User defined Exception in Stateless Java Class WS

    I'm experimenting with publishing some of my application's Java classes as web services under OC4J 10.1.2. I've been quite successfull to do so, but I'm stuck into a problem trying to have my class's methods throw my own type of exception and retrieving it at the client side.
    I'm using the proxies downloaded from the web service's automatic HTML page, and I see in the source code version that the proxy class specifically throws a org.apache.soap.SOAPException whenever there's a fault in the response message.
    What I've done is simply to create a type derived from Exception with a String (message) and an Integer (code) properties, with just my own constructor that accepts two parameters corresponding to that properties. Then I make the methods in my Java class throw that exception.
    I've tried both using both an Interface and a class, and also using just a class as parameters to StatelessWebServiceServlet / Web Service Assembler.
    I can't find anywhere in any docs that explains how this can be done in OC4J. I believe that throwing user-defined exceptions is included in J2EE 1.4 and so I think that there should be a way to do it in OC4J if it is compliant. Maybe there's no way, but I couldn't find any reference to that neither.
    I'll greatly appreciate any light on this issue.
    Thanks in advance
    Juan Alvarez Ferrando
    Mensaje editado por:

    Thank you for your answer.
    I'd like to know something more about how far does that limited support go, in case it could be of some use.
    On the other hand, and just for the sake of constructive discussion, though I've contemplated the option of encoding error conditions on the result type, I always found that to be an ugly style from a interface design standpoint (not ws specifically but in general system desing terms), and when I saw a standard way to communicate custom error information separated from normal response I thought it to be the right way to go. After all, exceptions are just the way Java implements this design principle that has also found a place in most currently successful software environments (PL/SQL, .Net, ...).
    I don't expect to extend the meaning and programmatic use of Java exceptions to my ws clients, but to be able to communicate detailed error condition information as the standards contemplate (faults), which as I understand from your kind answer is out of my reach in 10.1.2.
    I have no experience with other ws platforms but I'd like to believe that if wsdl:fault is in the standards, those claming compliance will support it to the extent necessary to make it usable and interoperable as it is the way the standard covers error communication (and so that's why it is included in 10.1.3). I also beleve this would bring better interoperability than our home-made result types including error information, that no other application without our custom specifications can understand.
    Also better interoperability would come from that than for example what I now see in 10.1.2, where all exceptions are communicated to the client with a faultcode of soap:Server, which I believe to have the standard meaning that there's a chance for the client to success retrying later without modifying it's request. This translation could be better suited for Java errors (unrecoverable) but not for all kinds of exceptions, and so in this question, custom exception support could also improve interoperability with systems that interpret SOAP fault codes.
    Thank you.
    Juan Alvarez Ferrando

  • How can I use User-Defined Aggregate Functions in Timesten 11? such as ODCI

    we are using Timesten 11 version and as per the documentation, it doesn't support User-Defined Aggregate Functions.
    So we are looking for alternatives to do it. Could you please provide your expert voice on this.
    Thanks a lot.
    As the following:
    create or replace type strcat_type as object (
    cat_string varchar2(32767),
    static function ODCIAggregateInitialize(cs_ctx In Out strcat_type) return number,
    member function ODCIAggregateIterate(self In Out strcat_type,value in varchar2) return number,
    member function ODCIAggregateMerge(self In Out strcat_type,ctx2 In Out strcat_type) return number,
    member function ODCIAggregateTerminate(self In Out strcat_type,returnValue Out varchar2,flags in number) return
    How can I use User-Defined Aggregate Functions in Timesten 11? such as ODCIAggregateInitialize ?

    Dear user6258915,
    You absolutely right, TimesTen doesnt support object types ( and User-Defined Aggregate Functions.
    Is it crucial for your application? Could you rewrite this functionality by using standart SQL or PL/SQL?
    Best regards,

Maybe you are looking for