How can you tell from the documentation....

How can you tell from the documentation if a method throws a specific exception?
If I am calling XMLNode.RemoveChild(OldChild as XMLNode)
Should I check that that node I’m trying to delete exists, or should i try / catch it with an exception case?

XMLNode is a class, instances of a class might be Nil, so NilObjectException. Obviously, XMLException if the XML is invalid. Maybe UnsupportedFormatException, but I’ve not used the XML classes much.

[quote=40611:@Brian O’Brien]How can you tell from the documentation if a method throws a specific exception?
[/quote]
Good question. Currently the documentation is structured

[quote]
Short synopsis
Properies

Methods

Examples

See also

[/quote]

Would be great if we had a Throws section after the Methods section.

Java “throws” exceptions. Xojo “raises” them. :slight_smile:

Anyway, a good suggestion. Please create a Feedback case for it so it can be considered.

Yeah, Xojo is more civilized! :smiley:

I throw rocks, but raise a beer
so yeah… more civilized :slight_smile:

I generally throw fits and raise my voice.

Not very civilized.

Why are there two ways to handle raised exceptions?
I’m referring to try / catch block and Exception blocks.

Three ways actually
Application.UnhandledException

Try/catch is more for handling exception at a particular place unlike Exception block that are global to the method.
The Try…catch[…Finally] syntax allows you to continue the execution of a method once you’ve dealt with the exception.
Exception blocks doesn’t allow that. When an exception is raised, all the code left to execute is inside the exception block.

I was leaning toward Exception blocks simply because i didn’t know what exception could be raised by a particular method.
i.e. like in C, catch … catches all exceptions where the type of exception is not known.
I may have misread the documentation but I saw no such thing in try / catch blocks.

If you want a catch-all, just use the Exception keyword w/o parameter. It’s also true for the Catch keyword.
If you need to access to the exception properties or methods, but still want a catch-all, then read the EndException and ThreadEndException note of the Exception page in the wiki.

[quote=40755:@Brian O’Brien]Why are there two ways to handle raised exceptions?
I’m referring to try / catch block and Exception blocks.[/quote]
Ancient history more than anything
The “exception” block at the end of the code is analogous to putting a try catch around the entire method (ie line 1 = try and the very last line is “catch”)
VB used this style

[quote=40761:@Brian O’Brien]I was leaning toward Exception blocks simply because i didn’t know what exception could be raised by a particular method.
i.e. like in C, catch … catches all exceptions where the type of exception is not known.
I may have misread the documentation but I saw no such thing in try / catch blocks.[/quote]
Try…Catch allows you to specify the type of exception you’re trying to catch. Perhaps I misunderstood your statement.

Exception block also allows to specify the type of exception to catch.

I don’t know why somethings take soo long to sink into this brain…

catch runtimeexception is the catch all for any exception?

like runtimeexception is the base class of IOException etc…

So If I don’t know what type of exception can be raised catching runtimeexception ‘catchs’ it.

The error parameter and type are both optional. So

try
   doSomething
catch
   msgbox "Something bad happened"
end try

or

try
  doSomething
catch err
  msgbox "Something bad happened"
end try

both catch all exceptions.

Note that you should be careful when catching exceptions indiscriminately like this, as the framework uses exceptions like EndE
xception and ThreadEndException to do actual work.

Thanks all, I was unaware of those to exception! I assume ‘ignoring’ is very bad.

There is an expression in French… "Je comprends vite mais il faut expliquer longtemps:
Translation, “I understand quickly but you have to explain for a long time.”
:wink: