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()
System.out.println(message);
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)
saveOld();
if (fc.showOpenDialog(null)== JFileChooser.APPROVE_OPTION)
readFile(fc.getSelectedFile().getAbsolutePath());
saveas.setEnabled(true);
So, should I use exception here or at the readFile method?
readfile:
private void readFile(String fileName)
try
String tmp = fileName.substring(fileName.length() -4, fileName.length());
if (!tmp.equals(".exe"))
FileReader r = new FileReader(fileName);
textarea.read(r, null);
r.close();
currentFile = fileName;
label.setText(currentFile);
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(StreamingSender.java:357)
[java] at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:228)
[java] at supercomputer.SuperIF_Stub.sendParam(SuperIF_Stub.java:60)
[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.
Thanks,
FarrukhFarrukh,
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.
regards,
Pedro Salazar. -
How to handle user defined exception from C#?
Hi:
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?
Thanks.Hi Gaff,
Is there a particular problem you're having doing this? It works as normal for me...
Cheers
Greg
PLSQL
=========
create or replace procedure throwsomething as
begin
raise_application_error(-20001,'kaboom');
end;
ODP
=====
class Program
static void Main(string[] args)
using (OracleConnection con = new OracleConnection())
con.ConnectionString = "user id=scott;password=tiger;data source=orcl";
con.Open();
using (OracleCommand cmd = new OracleCommand())
cmd.CommandText = "begin throwsomething;end;";
cmd.Connection = con;
try
cmd.ExecuteNonQuery();
catch (OracleException oe)
Console.WriteLine("caught " + oe.Message);
OUTPUT
========
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.
Regards
GorgeIf 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 - http://project.companyname.com/project
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 -
NameVirtualHost 13.xx.xx.xxx
<VirtualHost 13.xx.xx.xxx>
ServerName project.companyname.com
</VirtualHost>
That did not help. What am I missing?
Thanks.ATP,
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 http://mysite.us.oracle.com:80/pls/portal30, you can place the following directive in httpd.conf:
Redirect /portalhome http://mysite.us.oracle.com:80/pls/portal30
Then, if you try:
http://mysite.us.oracle.com/portalhome
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:
http://mysite.us.oracle.com/portalhome/url/folder/ONLINE_HELP
will redirect the user to the Online Help content area.
null -
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... http://download-uk.oracle.com/docs/cd/B32110_01/web.1013/b28218/qrybas.htm#BCFHDHBG
-
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.
UPDATE dg2.OD_PROJ_LOOKUP_TEMP o
SET Months_In_Stage_Cnt = select Months_In_Stage_Cnt_ret(o.project_id) from dual;
thanks
debhi,
CREATE FUNCTION fn_emp_ename (p_empno IN emp.empno%TYPE)
RETURN VARCHAR2
IS
v_ename emp.ename%TYPE;
BEGIN
SELECT ename
INTO v_ename
FROM emp
WHERE empno = p_empno;
RETURN v_ename;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
RETURN NULL;
WHEN OTHERS
THEN
RETURN NULL;
END fn_emp_ename;
SQL>
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;
EMP_NAME
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
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 .........
Thanks,
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 ?
Thanks,raise_application_error(-20001, 'error message');
Scott -
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 "http://www.example.org/medicalProblem/DiagnosedPastNeurologicalDeficit" rather than "http://www.example.org/medicalProblem/Diagnosed 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.
hongHi 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
Hi,
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 DamleHi,
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:
*XDIM_MEMBERSET COMP_CODE = COMP_CODE_1
*XDIM_MEMBERSET BUS_AREA = BUS_AREA_1
*XDIM_MEMBERSET VERSION = VERSION_1
*XDIM_MEMBERSET CURRENCY = AUD
*XDIM_MEMBERSET DATASRC = DATASOURCE_1
*XDIM_MEMBERSET GL_ACCOUNT = SALESREVENUE,PRICE,QUANTITY,DUMMYACC1
*XDIM_MEMBERSET TIME=2009.MAY,2009.JUN
*XDIM_MEMBERSET CUSTOMERCATEGORY = CUSTOMER_CAT_1
*XDIM_MEMBERSET PROFIT_CTR = PROFIT_CTR_1
*XDIM_MEMBERSET SEGMENT = SEGMENT1
*XDIM_MEMBERSET MEASURES = PERIODIC
*FUNCTION PRO(%VAR1%,%VAR2%)
[%VAR1%].CURRENTMEMBER.PROPERTIES("%VAR2%")
*ENDFUNCTION
*FOR %GL_ACC% = DUMMYACC1
*FOR %CV_TIM% = 2009.MAY,2009.JUN
#CUR_MTH = IIF(([GL_ACCOUNT].[%GL_ACC%],[TIME][%CV_TIM%]) = 1.,1,NULL)
*NEXT
*NEXT
*SELECTCASE #CUR_MTH
*CASE 1
#CURRENTMTH = PRO(TIME,TIMEID)
*ENDSELECT
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
Hi,
Can any one told me why we are using user define exception as ( -) 'Negative' range from -20,000 to -20,999. Why not Positive.
ThanksHi
Oracle error codes are negatives.
Ott Karesz
http://www.trendo-kft.hu -
User defined Exception in Stateless Java Class WS
Hi,
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:
user517323Thank 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
Hi
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
number
How can I use User-Defined Aggregate Functions in Timesten 11? such as ODCIAggregateInitialize ?Dear user6258915,
You absolutely right, TimesTen doesnt support object types (http://docs.oracle.com/cd/E13085_01/doc/timesten.1121/e13076/plsqldiffs.htm) 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,
Gennady
Maybe you are looking for
-
HP LaserJet 2200DN Printer Driver
I have an old 2200DN printer but up to now it has been a jewel. As a high school teacher, I used it for years to print materials for my classes. Somehow , in the last 24 hours, I've lost the connection between my printer and my computers. My HP Off
-
Compare PI 7.1 with IBM Message Broker (WBI)
Hi, I need some help on understanding the advantages and disadvantages of using PI 7.1 over Message Broker. (MB) I would like to a kind of comparative study for both the produts. Could any one help me to understand the two system in terms of a. Scala
-
Hooking up 2 computers to one display
I have a G-5- with OS 10.4.8 and a new MacPro with Leopard, and one 23 inch display. Is there any way to hook both computers up to one display and switch back and forth quickly?
-
Nokia lens not working and cant download - stuck
So apparently there was an update to lens yesterday? So i tried to update and it would stop midway with an error, now my len's icon which has the white building is now black and doesnt work. When i try to download, it goes halfway and wont fully dl
-
Macbook Pro and Thunderbolt display day to day work question
I have a late 2013 15 inch Retina Macbook Pro and recently bought a Thunderbolt display. When I'm in my office I use it on the display don't have the display anytime I'm not in the office. Given the larger pixel dimension on the display, when I'm in