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)); }
Hi Junior AX,
The purpose of the catch statement is to capture any error and continue without throwing a warning. If you need to raise an error, then don't use the catch method.
Hi Andre,
but in case of any error, I want to return a customized error message, I don't want to return ex.Message ... how can I do that without the catch?
For example, here I want the "customized error" to appear on the UI, instead of the "error" in init Method in class1
public classTest { public static void reset(A _a) { Class1 class1 = Class1::newFromParameters('x', _a); class1.send(); } } public Class1 extends classBase { public static Class1 newFromParameters(str _request, A _A = null) { Class1 class1 = Class1::construct(); Class1.parmRequest(_request); Class1.parmA(_a); return class1; } public void init() { throw error("error"); } } public classBase { public void init() { } public void send() { System.Exception ex; try { this.init(); //logic } catch(ex) { error("customized error"); } } }
If you don't get into the catch block, it means that either no exception was thrown or the type is different than the type of ex variable.
Hi Martin,
It reaches the catch(ex) as the break point is captured and I can see the error in ex but it doesn't get inside so it doesn't reach the error("customized error") line.
As you can see in class1 (init method) I throw an error by doing this
Throw error("error")
So the type should be captured by catch(ex) in classBase but why it didn't reach the customized error line?
Your assumption that if you see the value in ex variable means that the exception must have been caught makes sense, but it's not correct.
Why the break point jumped to catch(ex)?
And isn't throw error("error") captured by catch(ex)?
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.
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?
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.
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?
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 683 Most Valuable Professional
André Arnaud de Cal... 563 Super User 2025 Season 2
Sohaib Cheema 398 User Group Leader