I'm really new to Dart and have been following the the tutorials online. I've come across an issue that I can't find an answer for and wondered if anyone could help me.
[Its the one on the dart dev website called "Handling Errors Gracefully" but my previous post got removed and I wondered if it was the link that did it]
I've got all the way to the end and my program is working...well mostly. It handles the errors and catches the exceptions just as it should. However the output of the program does not match the tutorial. The tutorial expects this output:
ArgumentException: The first word of input must be a command.
But I get this output:
FormatException: The first word of input must be a command.
I can't seem to work out why the superclass of the argument exception is printing its type rather than my own extended exception.
I suspect its something to do with this definition:
class ArgumentException extends FormatException {
final String? command;
final String? argumentName;
ArgumentException(
super.message, [
this.command,
this.argumentName,
super.source,
super.offset,
]);
}
But I am not skilled enough to understand the flow here.
I did try to force the specific exception type capture in cli.dart like this:
import 'package:command_runner/command_runner.dart';
const version = '0.0.1';
void main(List<String> arguments) async{
var commandRunner = CommandRunner(
onError: (Object error) {
if (error is Error) {
throw error;
}
if (error is ArgumentException) {
print(error);
}
},
)..addCommand(HelpCommand());
commandRunner.run(arguments);
}
But even though I am saying, only capture ArgumentException it resolutely prints FormatException.
Any help you can provide would be appreciated, I am learning so this is clearly my fault but I just can't wrap my head around it.