cancel
Showing results for 
Search instead for 
Did you mean: 

Stop executing further code one a error occurs in catch block

Former Member
0 Kudos

Hi

I am executing a try catch and i handled a exception in that but i want to stop further execution of the code in that action so how can we do that?

Is there anything like exit command?

Thanks

Ninad

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

If you have handled an exception then you cannot stop the next set of instructions after the try-catch block to execute until and unless you are throwing a new exception from the catch block.

Another option can be having the try-catch block as the last instruction set.

There is no exit statement, but I think you can try firing an exit plug.

Regards,

Satyajit.

Former Member
0 Kudos

Hi Satyajit

I am reporting a error from message pool in catchblock and after that i don't want to run the next code and i can't write that at the end of the action because of the logic.

Besicaly i am taking a string from input field and checking wheter it is a long or not. and passing the sting to next logic. I can't set Log attribute directly to Input Field becase of some client requirements. I am posting my code bellow so please tell me what more we can do with that.

try
{
String idocNum = wdContext.currentParametersElement().getIdocnumber();
if(idocNum!=null)
{
long tempIdoc = Long.valueOf(idocNum).longValue();
}
}
catch(NumberFormatException e)
{
IWDMessageManager msgManager= this.wdComponentAPI.getMessageManager();
IWDAttributeInfo attributeinfo =  wdContext.nodeParameters().getNodeInfo().getAttribute("idocnumber");
		msgManager.reportContextAttributeMessage(this.wdContext.currentParametersElement()
     ,attributeinfo
     ,IMessageDTCComp.NOT_INT
     ,null
     ,true
   );
}

Thanks

Ninad

sridhar_k2
Active Contributor
0 Kudos

Hi,

Use msgManager.raisePendingException() in catch block as the last statement; to Stop execution, if any Exception occurs. It will stop executing the next lines.

Regards,

Sridhar

Message was edited by: Sridhar kanchanapalli

Former Member
0 Kudos

Hi Ninad,

I have modified your code a bit. Try this:


try
{
String idocNum = wdContext.currentParametersElement().getIdocnumber();
if(idocNum!=null)
{
long tempIdoc = Long.parseLong(idocNum);
}
}
catch(NumberFormatException e)
{
IWDMessageManager msgManager= this.wdComponentAPI.getMessageManager();
IWDAttributeInfo attributeinfo =  wdContext.nodeParameters().getNodeInfo().getAttribute("idocnumber");
		msgManager.reportContextAttributeMessage(this.wdContext.currentParametersElement()
     ,attributeinfo
     ,IMessageDTCComp.NOT_INT
     ,null
     ,true
   );
return;
}

Regards,

Satyajit.

Former Member
0 Kudos

Hi,

when the error occurs in your try block it will automatically transfer the control to catch block. so the further codes won't be executed.

regards

karthik