Try...catch cx_root
Hi experets,
I'm updating a abap program written by others.
PERFORM A
PERFORM B
PERFORM C
PERFORM D
because of file format issue, the program end at "PERFORM C". I can find the red flag in xml messages monitor
so I updated this section as below:
try
PERFORM A
PERFORM B
PERFORM C
PERFORM D
catch cx_root into l_oref.
send a e m a i l to me
endtry.
After I execute this program, I get a email, but show "execute successfully" in xml messages monitor.
Now my question is how to keep red flag in xml messages monitor after send exception infomation to me
Please help me,and thanks.
RESUME
or
catch CX_SY_ARITHMETIC_ERROR
Similar Messages
-
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 -
Try catch implementation in dynamic query
I am fetching values by dynamic selection (select a,b,..from (var)...) .
Eveytime if I am selecting garbage value of var it will throw dump . Can u tell me how we implement try catch method / exception handling method so that I can avoid dump in dynamic query
Appropriate answer will rewarded with points that is for sure .Here is the usage of th try statements ...
PARAMETERS number TYPE i.
DATA: result TYPE p LENGTH 8 DECIMALS 2,
oref TYPE REF TO cx_root,
text TYPE string.
TRY.
IF ABS( number ) > 100.
RAISE EXCEPTION TYPE cx_demo_abs_too_large.
ENDIF.
PERFORM calculation USING number
CHANGING result
text.
CATCH cx_sy_arithmetic_error INTO oref.
text = oref->get_text( ).
CATCH cx_root INTO oref.
text = oref->get_text( ).
ENDTRY.
IF NOT text IS INITIAL.
WRITE / text.
ENDIF.
WRITE: / 'Final result:', result.
FORM calculation USING p_number LIKE number
CHANGING p_result LIKE result
p_text LIKE text
RAISING cx_sy_arithmetic_error.
DATA l_oref TYPE REF TO cx_root.
TRY.
p_result = 1 / p_number.
WRITE: / 'Result of division:', p_result.
p_result = SQRT( p_number ).
WRITE: / 'Result of square root:', p_result.
CATCH cx_sy_zerodivide INTO l_oref.
p_text = l_oref->get_text( ).
CLEANUP.
CLEAR p_result.
ENDTRY.
ENDFORM.
<b>please see this link for detailed explaination of the TRY & ENDTRY ...</b>
<a href="http://">http://help.sap.com/saphelp_nw04/helpdata/en/a9/b8eef8fe9411d4b2ee0050dadfb92b/content.htm</a>
reward points if it is usefull......
Girish -
Dear all,
Can any body clear me what is code for try catch in SAP 4.6C? I tried the below code but the object type is doesn't exist. ( cx_root or x_sy_native_sql_error)
DATA: exc_ref TYPE REF TO cx_root, " cx_sy_native_sql_error,
error_text TYPE string.
LOOP AT it_sqlupdate.
try.
EXEC SQL.
insert into TBLSVBALSAP
( CoCode, SAPDocNo, PostDate, DocHdrTxt, GLAccount,
Amount, Text, RevDoc, CreationDate, CreationTime ) values
( :it_sqlupdate-c_code, :it_sqlupdate-sap_docno, :it_sqlupdate-p_date,
:it_sqlupdate-h_text, :it_sqlupdate-gl_acc, :it_sqlupdate-amt,
:it_sqlupdate-i_text, :it_sqlupdate-r_docno, :it_sqlupdate-c_date,
:it_sqlupdate-c_time )
ENDEXEC.
catch cx_sy_native_sql_error into exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text type 'I'.
endtry.
ENDLOOP.
Thanks.Hi,
I think, TRY CATCH Exception concept was not there in 4.6C, alternatively you can try with
CATCH SYSTEM-EXCEPTIONS.
Check the link below
http://help.sap.com/abapdocu/en/ABAPCATCH_SYS.htm
regards
Mahesh -
Catch CX_ROOT under 4.6C system
Hi guys,
I developed a report in 4.7 with try ... catch cx_root endtry constructs.
Now I implemented it at the customer's 4.6C system. It looks like there is no try endtry statement in this release, just catch endcatch. Furthermore I don't find a similar exception as cx_root in the 4.6C system.
Any hints?
Thanks,
ManeHi,
Class based exceptions are not supported in 4.6C. Even if you could create a class manually, the runtime would not handle it the same as a "class based exception".
http://help.sap.com/saphelp_nw04/helpdata/en/83/636d1412fc11d5991e00508b5d5211/frameset.htm
Regards,
Satish -
How to simulate a dml error in order to test try-catch code block inside a stored procedure
Hi,
What would be the easiest way to simulate a dml error in order to test a try catch block.
I would like to do it with a simple command from outside the stored procedure if possible.
I tried dropping the table that was updated but it hangs
Thanks,
DaniDropping the table that is the target of the procedure will give you an unpleasant surprise: the CATCH block will not fire. To wit, errors like missing tables can only be caught in outer scopes, but not in the procedure where the error occurs.
But you would add a fake constraint to a table which causes the update to fail. You need to do this in advance, not while running the procedure.
Erland Sommarskog, SQL Server MVP, [email protected] -
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 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 tablesHi 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 we have try/catch in a static block in a class?
hi All
i have a question about put a try/catch block in a static block in a class to catch exceptions that maybe thrown from using System.xxxx(). in my custom class, i have a static block to initialize some variables using System.xxx(). in case of any error/exception, i need to be able to catch it and let the caller know about it. i tried to put a try/catch block in the static block, and tried to rethrow the exception. but it is not allowed, how would i handle situation like this? thanks for your help and advise in advance.You could just swallow the exception inside try/catch
block, and instead of throwing it out, just set a
static variable to allow checking from outside
whether the initialization succeeded, or check within
the constructor / methods of this class for
successful initialization, and throw the exception
then. You could even save that exception in a static
variable for later.Ouch, ouch, you're hurting my brain. This would allow someone to ignore a (presumably) fatal error. Throw a RuntimeException as indicated. You can wrap a checked exception in an unchecked one if need be. -
RAISERROR with Try/Catch does not exit after exception in catch block
I am trying to propogate an error from within my proc out to the caller.
In the attached example I have 2 sets of try catch blocks.
I raiserror in the first
catch the error and then raiserror again. (I expect to exit)
I do not expect :
to get to print 'post test'
to get to second try block.
but this does not exit, instead the code flows as per 2 runs.
I do not understand the reason for the flows, as it seems counterintuitive to be raising an error but then still print following exceptions. I cannot seem to find any references that explains this behaviour.
running tests together results
print '-------------------------------------------------------'
print 'test 15'
exec test_raiseerror 15
print '-------------------------------------------------------'
print 'test 16'
exec test_raiseerror 16
print '-------------------------------------------------------'
print 'test 17'
exec test_raiseerror 17
print '-------------------------------------------------------'
print 'test 18'
exec test_raiseerror 18
print '-------------------------------------------------------'
'RESULTS'
test 15
error number provided: 15
Msg 50000, Level 15, State 1, Procedure test_raiseerror, Line 21
name hello 15
post test
15
Msg 50000, Level 15, State 1, Procedure test_raiseerror, Line 37
name hello 2 15
post test2
test 16
error number provided: 16
Msg 50000, Level 16, State 1, Procedure test_raiseerror, Line 21
name hello 16
post test
16
Msg 50000, Level 16, State 1, Procedure test_raiseerror, Line 37
name hello 2 16
post test2
test 17
error number provided: 17
post test
17
post test2
test 18
error number provided: 18
post test
18
post test2
Msg 50000, Level 17, State 1, Procedure test_raiseerror, Line 21
name hello 17
Msg 50000, Level 17, State 1, Procedure test_raiseerror, Line 37
name hello 2 17
Msg 50000, Level 18, State 1, Procedure test_raiseerror, Line 21
name hello 18
Msg 50000, Level 18, State 1, Procedure test_raiseerror, Line 37
name hello 2 18
run tests seperately
exec test_raiseerror 15
error number provided: 15
RESULTS 15
Msg 50000, Level 15, State 1, Procedure test_raiseerror, Line 21
name hello 15
post test
15
Msg 50000, Level 15, State 1, Procedure test_raiseerror, Line 37
name hello 2 15
post test2
exec test_raiseerror 16
RESULTS 16
error number provided: 16
Msg 50000, Level 16, State 1, Procedure test_raiseerror, Line 21
name hello 16
post test
16
Msg 50000, Level 16, State 1, Procedure test_raiseerror, Line 37
name hello 2 16
post test2
exec test_raiseerror 17
RESULTS 17
error number provided: 17
post test
17
post test2
Msg 50000, Level 17, State 1, Procedure test_raiseerror, Line 21
name hello 17
Msg 50000, Level 17, State 1, Procedure test_raiseerror, Line 37
name hello 2 17
exec test_raiseerror 18
RESULTS 18
error number provided: 18
post test
18
post test2
Msg 50000, Level 18, State 1, Procedure test_raiseerror, Line 21
name hello 18
Msg 50000, Level 18, State 1, Procedure test_raiseerror, Line 37
name hello 2 18
CODEBLOCK:
if object_id('test_raiseerror','P') is not null
drop proc test_raiseerror
go
create proc test_raiseerror(@id as int) as
begin
begin try
declare @name varchar(20)
select @name = 'hello'
raiserror('name %s %d',@id,1,@name,@id)
print 'next'
end try
begin catch
declare @errormessage nvarchar(4000)
declare @errornum int
select @errormessage = error_message()
, @errornum = error_severity()
print 'error number provided: ' + convert(varchar(2),@errornum)
raiserror(@errormessage, @errornum,1)
print 'post test'
end catch
begin try
select @name = 'hello 2'
raiserror('name %s %d', @id,1,@name, @id)
end try
begin catch
select @errormessage = error_message()
, @errornum = error_severity()
print @errornum
raiserror(@errormessage, @errornum,1)
print 'post test2'
end catch
end
go
sqlserver 2008 & 2008 R2There is a Connect that describes a similiar complaint. But basically a raiserror inside a catch block does not terminate the procedure, it will continue with any additional code in the CATCH and FINALLY unless it hits a return statement.
http://connect.microsoft.com/SQLServer/feedback/details/275308/have-raiserror-work-with-xact-abort -
Exception handling with try/catch in acrobat
Hi
I have a problem using a try/catch block in my acrobat document-script. Try to enter the following into the debugger-console:
try{nonexistentFunction();}catch(e){console.println('\nacrobat can't catch')}
and run it. The output will be:
nonexistentFunction is not defined
1:Console:Exec
acrobat can't catch
true
The whole point of a rty/catch block is for the application NOT to throw an exception, but instead execute the catch-part of the statement. However, acrobat does both: It throws an exception AND executes the catch-block.
Is there another way to suppress the exception, or to make the try/catch-block work as it's supposed to?> Also Adobe provides for free the JS or compiled file for Acrobat Reader to support the JS console.
Where is that file located ? How to install it or where to place it ?
What is the method referred by try67 on his site where he sells a product ?
Is that the same as the compiled file you refer to ? or did he sell his solution to adobe ?
It is helpful if people can get an idea of the nature of choices available and make informed decisions, than a cloak and dagger approach.
For some jobs that we have, I have been very frustrated by a consultant who wont even give basic info for transparent billing despite all assurances for privacy, as a result we are forced to do the job ourselves.
Dying Vet -
About the finally block of the try catch.
I know that finally block contains the code that will be executed in any condition of the try catch.
However, I think it is unneccessary, since the stack after the try catch stack will be executed any way.
Any one can help?
for example
try{
System.in.read();
catch(Exception e){}
finally
{ System.out.println("does this matter?");}and
try{
System.in.read();
catch(Exception e){}
System.out.println("does this matter?");However, I think it is unneccessary, since the stackafter the try catch
stack will be executed any way.That does assume that you catch and handle the error
appropriately.
Of course this is valid as well, and demonstrates
when you would WANT a finally clause.
Connection con = null;
Statement stmt = null;
try{
con = Database.getConnection();
stmt = con.createStatement("Select * from dual");
// maybe something throws an exception here?
finally{
if (stmt != null){
stmt.close();
if (con != null){
con.close();
The finally block here might throw a null pointer exception itself use
null!=stmt null!=stmt -
Return statement should put beyond try/catch clause??
The return statement should put beyond the try/catch clause, is that correct? Well,
I tried to put inside the try block, but it will have compile error though.
public String getValue()
String value;
try
catch(...)
return value;
please advise. thanks!!When a method returns a value, you must make sure that even if an exception is thrown and caught a value will be returned (or just throw the exception out of the method).
You can put a return clause as the last thing in the try block and another return clause after the catch block (this is where we go if we catch an exception so you probably want to return null). -
Return statement and Try Catch problem
Hi!!
I've got the next code:
public ResultSet DBSelectTeam(String query) {
try {
Statement s = con.createStatement();
ResultSet rs = s.executeQuery(query);
return rs;
} catch (Exception err) {
JOptionPane.showMessageDialog(null, "ERROR: " + err);
But I need a return statement in the catch-block, but I don't know what's the best option.
Help...
Many thanks.The error message is: "missing return statement", Yes, I know.
You have to either return from the catch statement, or throw from the catch statement, or return or throw after the catch statement.
The only ways your method is allowed to complete is by returning a value or throwing an exception. As it stands, if an exception is thrown, you catch it, but then you don't throw anything and you don't return a value.
So, like I said: What would you return from within or after catch? There's no good value to return. The only remotely reasonable choice would be null, but that sucks because now the caller has to explicitly check for it.
So we conclude that catch shouldn't return anything. So catch must throw something. But what? You could wrap the SQLE in your own exception, but since the caller is dealing with JDBC constructs anyway (he has to handle the RS and close it and the Statement), there's no point in abstracting JDBC away. Plus he has to deal with SQLE anyway in his use of the RS and Statement. So you might as well just throw SQLE.
So since you're going to just throw SQLE anyway, just get rid of the try/catch altogether and declare your method throws SQLException -
How to accept 2 strings in a class with try catch method..help!!
the program below will accept two strings and compare str1 and str2 if equal. this program uses functions. can any one help me with this?
import java.io.*;
public class StrCompare {
private BufferedReader takyoin = null;
//private BufferedReader intakyo = null;
* @param args
public StrCompare(){
takyoin = new BufferedReader(new InputStreamReader(System.in));
//intakyo = new BufferedReader(new InputStreamReader(System.in));
public String UserInput(){
public static void main(String[] args) {
// TODO Auto-generated method stub
}What are you talking about? There is no such thing as "try-catch-methods", and there are no functions but methods.
Strings by the way have their own means of comparision. Apart from that: do your own homework.
Maybe you are looking for
-
Macbook Retina screen black coating issue
My MBP Retina 13" -Oct '13 has developed a discolouration of the black screen coating on the top left and bottom left sides. It is visible in bright light/sunlight and seems that the black colour is wearing off. I have been extremely careful about pe
-
I've imported a movie which will not fit onto DVD pro. Are there any settings in DVD pro that will adjust the aulity so I can fit it on in it's entirety? Thanks
-
I'm trying to get to the Ultra Search home page, however the following link: http://otn.oracle.com/products/ultrasearch/index.html brings up Oracle Warehouse Builder 10g.
-
Hi there, I'm currently designing a clothing website that uses add to basket and then has a checkout. I was just wondering what your opinions were on the best way to go about creating this. After looking at a few other sites I've found that they link
-
SSD in Optical Bay 2011 MacBook Pro 13"
So I have a MacBook Pro 8.1, late 2011 13". I want to put an SSD in it using OptiBay or an equivalent. I don't want to put the HDD in the optibay because I want all the protection the original slot provides for the HDD. I have read a lot about incomp