https://kotlinlang.org logo
Title
h

Hamza

05/27/2018, 2:46 AM
one more question, how do I make a function that returns nothing without throwing an Exception?
a

Allan Wang

05/27/2018, 6:47 AM
Nothing indicates that it essentially halts the program. You can throw an exception or call system exit. I believe there is a kotlin function called exit that returns nothing, doing exactly that If you are referring to Java's void, then return unit (you don't have to specify that in the method header)
h

Hamza

05/27/2018, 6:55 AM
i want the formet. to exit. but i don’t want the program to exit. i just want to simulate an exception without throwing an exception (so only that thread stops). so like if im making a discord bot, it stops the program there, not everywehre
k

karelpeeters

05/27/2018, 7:27 AM
If you throw an exception and no one catches it only that thread stops.
o

oleksiyp

05/27/2018, 1:49 PM
Ok so, just as an idea you can suspend execution and never resume it i.e. try to apply coroutines
a

Allan Wang

05/27/2018, 3:48 PM
If you want, you can also use boolean returns to propagate responses. As in return true to continue, false otherwise etc
h

Hamza

05/27/2018, 11:38 PM
Alan thanks for the great idea!