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
Similar Messages
-
How can we handle user defined exceptions in ejbStore() of entity bean
Accroding to my knowledge in ejbStore we can not handle user defined exceptions. Can anybody help on this????
In my case I am calling a method from ejbsotre() . In that method i wanted to put some checks according to that i wanted to throw exceptions.
In this case how would I handle exceptions.
Can you suggest in this case,please !!! -
Return User Defined Exceptions from SP
Hi,
Is it possible to return user defined business exceptions from a stored procedure to the dotnet app. through ODP. NET( equivalent to the throw keyword in Java)?
I would prefer to handle all of the oracle expections in the try catch block of the C# code.
Thanks,
PeeyushIs your question how to return a custom exception from PLSQL? You'd use RAISE_APPLICATION_ERROR for that, and yes it would propagate via ODP to the calling application.
Here's a simple dumb example:
create or replace procedure raise_my_error as
begin
raise_application_error(-20001,'something bad happened');
end;
Hope it helps,
Greg -
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.
% -
Handle user defined exception in stored procedure
Dear all,
I'm using JDev 11.1.1.4.0
In my application I'm calling the stored procedure with only in parameters using the Example 37-9 http://download.oracle.com/docs/cd/E17904_01/web.1111/b31974/bcadvgen.htm#ADFFD1056
In my stored procedure I have user defined exception, like:
create or replace procedure ...
AS
e_otwarty EXCEPTION;
//some code
EXCEPTION
WHEN e_otwarty THEN
dbms_output.put_line('Masz juz otwarty raport');
// or what should I do here ??
END;I want to display the message in the popup window in my ADF application. How can I do that ?
Regards,
Wojtek.raise_application_error(-20001, 'error message');
Scott -
How to Pass User-defined Parameters from Forms to Reports
Hi!I am trying to launch an existing report from a form then spool it into a PDF file. I have been successful in passing the report properties using SET_REPORT_OBJECT_PROPERTY built-in and I am also able to launch the report using RUN_REPORT_OBJECT built-in. My problem is, I cannot seem to pass the user defined parameters from my form to the report eventhough I am using the same variable names.
this is a part of my code:
repid := Find_Report_Object('ACPPRACS');
Set_Report_Object_Property(repid, REPORT_EXECUTION_MODE,BATCH);
Set_Report_Object_Property(repid, REPORT_DESTYPE,FILE);
Set_Report_Object_Property(repid, REPORT_DESNAME,'C:\TMP\ACS01.PDF');
Set_Report_Object_Property(repid, REPORT_DESFORMAT,'PDF');
Set_Report_Object_Property(repid, REPORT_OTHER,'PF_NBO_CD='| |'"'| |:acs.nbo| |'"');
v_rep := RUN_REPORT_OBJECT(repid);
Hope you can help me soon. Thanks!first of all u will create a paramlist
then add_paramter to this list
and then pass this list to the report
by using run_product.
i think this is all.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Jenny ([email protected]):
Hi!I am trying to launch an existing report from a form then spool it into a PDF file. I have been successful in passing the report properties using SET_REPORT_OBJECT_PROPERTY built-in and I am also able to launch the report using RUN_REPORT_OBJECT built-in. My problem is, I cannot seem to pass the user defined parameters from my form to the report eventhough I am using the same variable names.
this is a part of my code:
repid := Find_Report_Object('ACPPRACS');
Set_Report_Object_Property(repid, REPORT_EXECUTION_MODE,BATCH);
Set_Report_Object_Property(repid, REPORT_DESTYPE,FILE);
Set_Report_Object_Property(repid, REPORT_DESNAME,'C:\TMP\ACS01.PDF');
Set_Report_Object_Property(repid, REPORT_DESFORMAT,'PDF');
Set_Report_Object_Property(repid, REPORT_OTHER,'PF_NBO_CD='| |'"'| |:acs.nbo| |'"');
v_rep := RUN_REPORT_OBJECT(repid);
Hope you can help me soon. Thanks!<HR></BLOCKQUOTE>
null -
How to handle user-defined character in java??
Dear all,
i am new to internalization and localization.
i am now porting an application from vb.net to java.
the vb.net version can handle (input/output [to file, screen, database] ...etc) user defined character (charset is big5 + extra characters) transparantly.
what i need to do is update the file EUDC.tte in windows (which seems have native charset codepoint to unicode codepoint info) ..
could anybody tell me how can i achieve the same thing in java??
thank you.
lsppslkwan wrote:
Hi DrClap,
it seems i need to write CharsetProvider, charsetdecoder, charsetencoder...etc...
do you have example / sample for me to follow???? I googled for "java charsetprovider example" and got one as the first hit.
btw, is it possible to replace the default big5 charset implementation with my own one so that the existing code can take advantage of the my own charset classes???You don't want to replace the default, just specify which one to use when needed. Pretty much any operation that involves charsets lets you specify which one to use. If your current code relies on the default, then you should change that. -
Java: how to handle user-defined character (UDC)??
Dear all,
i am new to internalization and localization.
i am now porting an application from vb.net to java.
the vb.net version can handle (input/output [to file, screen, database] ...etc) user defined character (charset is big5 + extra characters) transparantly.
what i need to do is update the file EUDC.tte in windows (which seems have native charset codepoint to unicode codepoint info) ..
how can i achieve the same thing in java??
thank you.
lsppslkwan wrote:
Hi DrClap,
it seems i need to write CharsetProvider, charsetdecoder, charsetencoder...etc...
do you have example / sample for me to follow???? I googled for "java charsetprovider example" and got one as the first hit.
btw, is it possible to replace the default big5 charset implementation with my own one so that the existing code can take advantage of the my own charset classes???You don't want to replace the default, just specify which one to use when needed. Pretty much any operation that involves charsets lets you specify which one to use. If your current code relies on the default, then you should change that. -
How to raise the user defined Exceptions in XI ?
Hi All
I am learning XI ...i want know how to set up the user defined Exceptions
in XI?
Where and What are the settings need to be done ?
Same time where can check the LOG file ? to see all the server information ?
Welcome to your answers
Regards
RakeshRakesh,
Check this weblogs which will guide you:
/people/bhavesh.kantilal/blog/2006/07/25/triggering-xi-alerts-from-a-user-defined-function
/people/alessandro.guarneri/blog/2006/01/26/throwing-smart-exceptions-in-xi-graphical-mapping
/people/stefan.grube/blog/2005/12/30/test-user-defined-functions-for-the-xi-graphical-mapping-tool-in-developer-studio
Also check this thread:
Mapping test throughs exception for UDF that does'nt exist anymore
---Satish -
How to catch the user defined exception in application service
Hi All,
How to catch the user defined exception in application service when it is throwed by the external service..
Regards,
Thirumurugan.Hi,
Thanks for your reply,
Actually I am calling validate Login method of External service from the application service. When the login fails, my external service will throw user defined Exception.I want to catch the user defined Exception.
But in the application service , validate Login method can catch only Invocation Exception and Engine Exception.
These two exception are present in the Application service remote interface.
public com.sap.comptest.extsrv.accrjavawsvi__document.output.
Ns1_validateLoginResponse validateLogin(com.sap.comptest.extsrv.accrjavawsvi__document.input.Ns1_validateLogin input) throws com.sap.caf.mp.base.exception.InvocationException, com.sap.caf.mp.base.exception.EngineException;
User defined exception is not present there. When i include the webservice as external service in CAF, it suppossed to generate the java file for the custom exception of validate Login method and this generated file should be included in the application service remote interface..
public com.sap.comptest.extsrv.accrjavawsvi__document.output.
Ns1_validateLoginResponse validateLogin(com.sap.comptest.extsrv.accrjavawsvi__document.input.Ns1_validateLogin input) throws com.sap.caf.mp.base.exception.InvocationException, com.sap.caf.mp.base.exception.EngineException,
(generated file name of user defined Excpetion.
Then only validate login method of application service can catch the user defined Exception which is thrown by the external service.
regards,
Thirumurugan.p -
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 -
Help in user defined exception handler
Hi
Can some one help in solving this error .
when i run my procedure i get this error which is given below .
ORA-06510 PL/SQL unhandeled user defined exception at line 7
Procedure FMG_EXTRACT_MOTORBIKE_NEWBUS (P_NSSC_YN VARCHAR2) IS
l_start date;
l_end date;
cursor motorbike_rec is
select
c.id,
k.id pak_id,
p.ref,
i.description,
i.current_status,
i.premium,
i.sum_insured,
mv.registration_no,
mv.cc_rating,
nl.ncl_level,
nl.percentage_discount,
dp.full_name main_driver,
dpd.birth_date,
e.user_name entered_by,
ep.full_name emp_name,
fmg_get_imposed_terms(i.id,'. ',';') imposed_terms
from
fmg_clients c,
fmg_client_paks k,
fmg_policies p,
fmg_Policy_items i,
fmg_mv_usages u,
fmg_people dp,
fmg_people_details dpd,
fmg_employees e,
fmg_people ep,
fmg_motor_vehicles mv,
fmg_ncb_levels nl
where i.date_created>=l_start
and i.date_created<l_end
and i.pol_id=p.id
and p.ctp_id=k.id
and k.cli_id=c.id
and i.id=u.poi_id(+)
and u.per_id=dp.id(+)
and dp.id=dpd.per_id(+)
and i.id=mv.poi_id(+)
and i.ncl_id=nl.id(+)
and ( (i.pit_pro_code in ('TFF','FMC','FMT','FMF','FBK','PMC','TPO','MCL'))
or (i.pit_pro_code = 'CMV' and i.pit_code = 'MCL')
or (i.pit_pro_code = 'PMS' and i.pit_code = 'MCL')
or (i.pit_pro_code = 'PMT' and i.pit_code in ('MCT','MCF'))
and i.user_created=e.user_name
and ( (e.business_unit='BCC' and P_NSSC_YN='Y') OR (nvl(e.business_unit,'X')<>'BCC' and P_NSSC_YN='N') )
and e.per_id=ep.id;
l_file UTL_FILE.FILE_TYPE;
l_file_name varchar2(100);
l_data VARCHAR2(4000);
BEGIN
if P_NSSC_YN='Y' then
l_start := trunc(sysdate)-1;
l_end := trunc(sysdate);
l_file_name := 'MotorCycle_Daily_'||to_char(l_start)||'.csv';
l_file := utl_file.fopen( fmg_re_filepath('SSC'), l_file_name, 'W' );
else
l_start := to_date('01-' || to_char(sysdate-28,'MM-YYYY'));
l_end := last_day(to_date('01-' || to_char(sysdate-28,'MM-YYYY')));
l_file_name := 'MotorCycle_Monthly_'||to_char(l_start)||'_'||to_char(l_end)||'.csv';
l_file := utl_file.fopen( fmg_re_filepath('GAU'), l_file_name, 'W' );
end if;
l_data := '"Client ID","Pak ID","Policy Ref","Item Desc","RegoNo","CC","Item Status","Premium","Sum Insured",' ||
'"NCB Level","NCB%","Main Driver","Birth Date","Imposed terms","EnteredBy","Employee Name"';
utl_file.put_line(l_file, l_data );
for i in motorbike_rec loop
l_data :=
to_char(i.id) || ',' ||
to_char(i.pak_id) || ',' ||
i.ref || ',' ||
'"' || i.description || '",' ||
'"' || i.registration_no || '",' ||
to_char(i.cc_Rating) || ',' ||
i.current_status || ',' ||
to_char(i.premium) || ',' ||
to_char(i.sum_insured) || ',' ||
to_char(i.ncl_level) || ',' ||
to_char(i.percentage_discount) || ',' ||
'"' || i.main_driver || '",' ||
to_char(i.birth_date) || ',' ||
'"' || i.imposed_terms || '",' ||
i.entered_by || ',' ||
'"' || i.emp_name || '"' ;
utl_file.put_line(l_file,l_data);
end loop;
utl_file.fclose( l_file );
exception
when others then
if utl_file.is_open(l_file) then
utl_file.fclose( l_file );
end if;
raise;
END;What does fmg_re_filepath('SSC') return? Are their sufficient rights with Oracle user on the location that is returned by this function?
Which OS are you using? -
Trapping user defined exceptions in forms
hi guys..
i have a database trigger that goes like that:
CREATE OR REPLACE TRIGGER loan_trig
before insert on loans
for each row
declare
lcount number(10);
duplicate_loan exception;
begin
select count(1) into lcount from loans
where branch_code=:new.branch_code
and client_code=:new.client_code;
if lcount>0 then
raise duplicate_loan;
end if;
end;
now how do i trap this user defined exception on the form ?
declaring the exception in the form & handling it in the exeption handler section doesn't seem to work and i get the following error:
"when button pressed trigger raised unhandled exception
ora-06510"
ora-06510:unhandled user-defined exception
what am i doing wrong?
if i have to handle the exception in the trigger body how do i do that?
thankx in advance..Hello,
raise duplicate_loan; won't avoid the trigger to insert and commit. If you really want to avoid the insertion, use the raise_applicatrion_error() instead.
For instance : Raise_Application_Error( -20001, 'Insertion cannot be validated' );Then in your Forms module, you can catch it like this:
Begin
Insert Into ...
when others then
LC$Erreur := Substr( SQLERRM,1 , 500 );
LN$err_code := ABS(SQLCODE);
If LN$err_code = 20001 Then ...
End;
...Francois -
Validation returns : no data found + unhandled user-defined exception
Hi, I'm working with Application Express 4.1.1.00.23.
I have an application for timesheet management.
On one page, I've got a report (not interactive) in which you can enter the hours you've worked. First you add a free line, choose the task and then enter the hours you've spent.
You can only have one empty line at a time. If you try to add a line when you already have an empty line, a validation will display an error. It worked fine in version 3.2. Now we upgraded to 4.1 and get a weird error :
1) The validation msg appears fine
2) The report appears fine
3) There is a msg at the end of the report saying :
report error:
ORA-01403: no data found
ORA-06510: PL/SQL: unhandled user-defined exception
Could somebody point out the source of this problem ?
Thank you!
Here is the debug :
0.31117 0.00204 parse query as: FEUILLES_DE_TEMPS 4
0.31319 0.07865 ...Execute Statement: select NULL "CHECK$01", NULL "nom_projet2", NULL "NO_TACHE_ENTRE", NULL "NO_TACHE", NULL "NO_SEMAINE_EMPLOYE", NULL "NOM_TACHE", NULL "Tâches", NULL "SEQUENCE", NULL "Heures dim", NULL "DIM", NULL "Heures lun", NULL "LUN", NULL "Heures mar", NULL "MAR", NULL "Heures mer", NULL "MER", NULL "Heures jeu", NULL "JEU", NULL "Heures ven", NULL "VEN", NULL "Heures sam", .........
0.39191 0.00158 print column headings 4
0.39342 0.02546 rows loop: 500 row(s) 4
0.41889 0.00087 report error: ORA-01403: no data found ORA-06510: PL/SQL: unhandled user-defined exception
.....Hi, thanks for your answer. Here is the validation we are executing. I'm pretty sure its fine since count(*) always return a value (plus we see V2 in the debug...) :
declare
l_count number;
begin
apex_debug_message.enable_debug_messages(7);
apex_debug_message.log_message('-----------------------------------V1----------------------------------');
-- get remaining empty tasks count
SELECT count(*) into l_count
FROM VIEW_TACHE_SYSTEME
WHERE NO_TACHE NOT IN (SELECT DISTINCT NO_TACHE FROM TACHE_JOUR WHERE NO_SEMAINE_EMPLOYE = :P36_NO_SEMAINE_EMPLOYE);
apex_debug_message.log_message('-----------------------------------V2----------------------------------');
apex_debug_message.log_message(l_count);
if l_count = 0 then
return 'Veuillez utiliser la tâche vide avant d''ajouter une ligne.';
else
return null;
end if;
end;
Here is the debug :
0.14643 0.00318 ...Validation "ADD_ROW_VALIDATION" - Type: FUNC_BODY_RETURNING_ERR_TEXT 4
0.14961 0.00318 ...Execute Statement: declare function x return varchar2 is begin declare l_count number; begin apex_debug_message.enable_debug_messages(7); apex_debug_message.log_message('-----------------------------------V1----------------------------------'); -- get remaining empty tasks count SELECT count(*) into l_count FROM VIEW_TACHE_SYSTEME WHERE NO_TACHE NOT IN (SELECT DISTINCT NO_TACHE FROM TACHE_JOUR WHERE NO_SEMAINE_EMPLOYE = :P36_NO_SEMAINE_EMPLOYE); apex_debug_message.log_message('-----------------------------------V2----------------------------------'); apex_debug_message.log_message(l_count); if l_count = 0 then return 'Veuillez utiliser la tâche vide avant d''ajouter une ligne.'; else return null; end if; end; return null; end; begin wwv_flow.g_computation_result_vc := x; end; 4
0.15280 0.01299 -----------------------------------V1---------------------------------- 6
0.16578 0.00310 -----------------------------------V2---------------------------------- 6
0.16888 0.00235 0 6
0.17123 0.00225 ......Result = Veuillez utiliser la tâche vide avant d'ajouter une ligne. 4
0.17347 0.00276 ......Did NOT pass 4
0.17624 0.00314 Add error onto error stack 4
0.17938 0.00343 ...Error data: 4
0.18280 0.00327 ......message: Veuillez utiliser la tâche vide avant d'ajouter une ligne. 4
0.18607 0.00446 ......display_location: INLINE_IN_NOTIFICATION 4
0.19053 0.00323 ......is_internal_error: false 4
0.19375 0.00323 ......error_backtrace: - PL/SQL Call Stack - object line object handle number name c000000382130f30 717 package body APEX_040100.WWV_FLOW_ERROR c000000382130f30 833 package body APEX_040100.WWV_FLOW_ERROR c00000039da9b5c8 154 package body APEX_040100.WWV_FLOW_VALIDATION c00000039da9b5c8 363 package body APEX_040100.WWV_FLOW_VALIDATION c00000039da9b5c8 784 package body APEX_040100.WWV_FLOW_VALIDATION c00000039da9b5c8 905 package body APEX_040100.WWV_FLOW_VALIDATION c00000039d1142c8 10005 package body APEX_040100.WWV_FLOW c000000381287050 31 anonymous block -
How to import user defined class in UIX page?
Does anyone know how to import user defined class in UIX page so that the class can be called in the javascript in the UIX ?
Thks & Rgds,
Bennywhat you are referring to is not javascript.
it is JSP scriptlets. These are very different.
In order to keep a strict separation between View and Controller, it is not possible to run arbitrary java code from within your UIX code.
However, you can run java code from within a UIX event handler; see:
http://otn.oracle.com/jdeveloper/help/topic?inOHW=true&linkHelp=false&file=jar%3Afile%3A/u01/app/oracle/product/IAS904/j2ee/OC4J_ohw/applications/jdeveloper904/jdeveloper/helpsets/jdeveloper/uixhelp.jar!/uixdevguide/introducingbaja.html
event handler code is run before the page is rendered.
Maybe you are looking for
-
Hi i have problem one of my bank cheque clearing account i was not check open item management now i have to change that account to open item management but it is not accepting i had heard that ther is programe for effect open item management to past
-
How to implement the record count on the page
Dear, I have a basic search page, results region with a simple table. I need to show the total number of records returned by a search query. Suppose I create messageStyledText "counter" bean to show the result. The result will be calculated in the Pr
-
I found a lot tutorials out there showing you how to make one drop down list populates another one but most of them either render the second ddl html in javascript (dealing with DOM crap!) or use third-party controls such as ATLAS. Then I decided to
-
My Iphone 6 Screen has been bugging Please Help
My Iphone 6 Screen has been bugging out lately it bounces up and down and just gets really blurry. Does anyone know how to fix this?
-
Problem encountered in Cluster Communication for WLS 6.1 SP2
Hi, Currently, we have an admin server with 2 clusters of managed servers. We realise that the managed server in the cluster will communicate with the other servers in the other cluster using port 7001. Is ther