Hi,
the code reaches catch(ex) but it doesn't get inside and It doesn't print the error inside
catch (ex) { ClassName className = classId2Name(classIdGet(this)); throw error(strFmt("error in class: %1 ", className)); }
Please don't forget using Insert > Code to paste source code.
You don't have 'catch; between ttsbegin and ttsbegin, therefore it'll work, unless the whole code is called from another transaction. Context is important.
Hi Martin,
When we create a new country..it happens in logisticsAddressSetup form
There is a "new command button", on clicked method it calls logisticsAddressCountryRegion_ds.create() (tts level still 0) then standard code from formUtil..when it goes to insert I can see level became 1..so where should I catch it?
When you say after transaction...you mean that try and catch should be after ttscommit?
So in general..the below won't catch exceptions? And it won't print customized? If yes how to change it to make it print customized?
Try
{
Ttsbegin;
Throw error("error");
Ttscommit;
}
Catch(ex)
{
Throw error(" customized error");
}
As I thought.
Why exceptions can't be caught in transactions? Because the system is implemented in such a way.
What you can do about it? Nothing. You just need to accept the reality.
The place where you can catch exceptions is after the transaction. You clearly have no idea where it is, but if you want to do such a thing, you'll need to find it. Note that you have the sequence of calls in debugger, so you can look at them and find which one added the transaction.
Hi Martin,
Looking at auto variables after next insert() for country table and before calling classTest
It says Ttslevel = 1
I'm still not sure what I should do now and why the Ttslevel causes this
I didn't say that you added a transaction in insert() - I said that insert() is likely called from inside a transaction.
Look at Auto variables in the debugger to see the transaction level. Or call appl.ttsLevel() in your code. Just trying to guess what's going isn't usually very successful, as you see, therefore it's important to collect facts.
Hi Martin,
There is no insert method in the standard logisticsAddressCountryRegion table to look if there is transaction
And in my extension for the insert method, I only added code after insert to call classTest
So I'm not sure what is wrong..how can I fix the issue and make customized error appear?
Let me simplify your code used for demonstration:
internal final class CatchDemo { public static void main(Args _args) { System.Exception ex; try { throw error("error"); } catch (ex) { error("customized error"); } } }
When I run it, the exception gets caught as expected and "customized error" text is added to infolog.
Try it and see it for yourself.
Then look again at the transaction level when calling your code from insert(). I'm pretty sure that you'll find that it is in transaction, which explains the behaviour.
Hi Martin,
What do you mean type of ex variable...as the code shows in my previous reply to Andre.. it's of type system.exception
As for the transaction there is no transaction...but the method that calls classTest is the insert for CountryRegion table....where I made an extension of the insert method to call classTest
What should I do?
1) It's how the debugger works.
2) As I already mentioned, it depends on the type of ex variable. It's also possible that your code is in a transaction, where you can't catch (most types of) exceptions.
Hi Martin,
Why the break point jumped to catch(ex)?
And isn't throw error("error") captured by catch(ex)?
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,836
Most Valuable Professional
nmaenpaa
101,156