I have an object created from Java class `IntegerS...
# getting-started
v
I have an object created from Java class
IntegerStringConverter
that trows exceptions like
java.lang.NumberFormatException
, is it possible to catch or suppress them without
try ... catch
block?
k
Consider taking advantage of
String#toIntOrNull
instead
Then you won’t have to deal with any exception/catching
v
@kingsley thanks, for these days I've tried it. And finally stayed with setting custom
TextFormatter
(and overriding TFX functions, and writing custom
TableCell
) to prevent this exception ever happen. But I could not find how to push back those exceptions without user interaction. I.e. when such exception arises, and we see the call stack, exiting this exception dialog, program returns to the moment before the exception. So I supposed that it can be done automatically and silently
k
not sure I understand the dialog you’re describing do you mean the app is crashing? in that case, try/catch will silence the crash. However, you can just use the method I mentioned earlier, so you only have to check for
null
instead of catching exceptions which is much more expensive
v

https://kotlinlang.slack.com/files/UCQRGDEB1/FD87A5CMP/screenshot_from_2018-10-07_08-31-50.png

This dialog. I would like to know, how to prevent it showing (and suppress error stack in stdout). It's kinda advanced exception handling
And without any
try ... catch
, and without avoiding this error changing logic. I.e. I want this error to happen, but silently