try... catch... statement

How can I use try catch statement, if I am not sure what exact error exception is?

I currently work on a project, to move a .net project into xojo. There is serial port session, usually in vb.net,

Try serialport1.open() ... Catch ex as Exception messagebox("bla bla bla") End Try

So generally speaking, is there a similar method in xojo to catch any exception in the try code block? Or, what’s the exact exception, if the serial port open failed or doesn’t exist or been used by other program? Thanks!

[quote=44280:@BO CHEN]How can I use try catch statement, if I am not sure what exact error exception is?

I currently work on a project, to move a .net project into xojo. There is serial port session, usually in vb.net,

Try serialport1.open() ... Catch ex as Exception messagebox("bla bla bla") End Try

So generally speaking, is there a similar method in xojo to catch any exception in the try code block? Or, what’s the exact exception, if the serial port open failed or doesn’t exist or been used by other program? Thanks![/quote]
Reading this right now, I do not actually know what exception you use but I recommend learning for yourself by making the error occur so then it will tell you what exception you need to catch and btw do not forget to have ‘#pragma BreakOnExceptions false’ above that code. And if there is any code below your try…catch in the method then set BreakOnExceptions back to true. So Xojo will not warn you every time this error occurs. Btw, in this case, you can write ‘catch RuntimeException’, instead of ‘catch ex as exception’. But writing it the way you are writing it is standard anyway, so no worries.

Please let me know if I have confused as I am happy to help. :wink:

[quote=44286:@Oliver Scott-Brown]Reading this right now, I do not actually know what exception you use but I recommend learning for yourself by making the error occur so then it will tell you what exception you need to catch and btw do not forget to have ‘#pragma BreakOnExceptions false’ above that code. And if there is any code below your try…catch in the method then set BreakOnExceptions back to true. So Xojo will not warn you every time this error occurs. Btw, in this case, you can write ‘catch RuntimeException’, instead of ‘catch ex as exception’. But writing it the way you are writing it is standard anyway, so no worries.

Please let me know if I have confused as I am happy to help. ;)[/quote]

Hey, I just tried to open some none-exist com port in my program, somehow, there is no exception reuturned. That’s wired. So I don’t know xojo deal with opening a com port. I read the doc of xojo, serial.Open() as a boolean. Does this means even if the com port is not exist in the system, xojo can still try to open it but return a false value to Serial. Open() method and there is no exception to throw out?

Correct. Not everything in Xojo raises and exception when an error occurs.

is there a way to put in the docs what does raise an exception and what doesnt?

I’m pretty sure that the LR topics do state when things raise exceptions, but if things are missing just let me know.

I don’t know that it makes much sense to note things that do not raise an exception.

Sorry for my ignorance. I thought that Xojo raises exceptions for all exceptions. Atleast I learned something. :wink: