Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 25, 2014 Exception "error" message without stacktrace | ||||
---|---|---|---|---|
| ||||
I caught a FileException, and want to print out the descriptive error, but not the stacktrace. I cannot see how to do this at the moment. I only see the toString function. i.e. in the case below I would like to obtain "c:/temp\junk: The directory is not empty." or something similar, but not the stack trace. faild to remove c:/temp\junk (error: std.file.FileException@std\file.d(1462): c: /temp\junk: The directory is not empty. ---------------- 0x00412938 0x004021C2 0x004025B8 0x0040E228 0x0040E1FB 0x0040E114 0x0040A2CB 0x761FED5C in BaseThreadInitThunk 0x77D837EB in RtlInitializeExceptionChain 0x77D837BE in RtlInitializeExceptionChain) |
March 25, 2014 Re: Exception "error" message without stacktrace | ||||
---|---|---|---|---|
| ||||
Posted in reply to Spacen Jasset | On Tuesday, 25 March 2014 at 14:43:18 UTC, Spacen Jasset wrote:
> I caught a FileException, and want to print out the descriptive error, but not the stacktrace.
Try writing the exception's 'msg' field (it's a string).
There is also 'file' and 'line'. See the class Throwable (in object.d or object.di) and the FileException class in std.file (it has some additional fields like errno).
|
March 25, 2014 Re: Exception "error" message without stacktrace | ||||
---|---|---|---|---|
| ||||
Posted in reply to Spacen Jasset | Am 25.03.2014 15:43, schrieb Spacen Jasset:
> I caught a FileException, and want to print out the descriptive error, but not the stacktrace. I cannot see how to do this at the moment. I only see the toString function.
>
> i.e. in the case below I would like to obtain "c:/temp\junk: The directory is not empty." or something similar, but not the stack trace.
>
> faild to remove c:/temp\junk (error:
> std.file.FileException@std\file.d(1462): c:
> /temp\junk: The directory is not empty.
> ----------------
> 0x00412938
> 0x004021C2
> 0x004025B8
> 0x0040E228
> 0x0040E1FB
> 0x0040E114
> 0x0040A2CB
> 0x761FED5C in BaseThreadInitThunk
> 0x77D837EB in RtlInitializeExceptionChain
> 0x77D837BE in RtlInitializeExceptionChain)
Exceptions have a msg or message (cant remember which one) attribute, you can use it to get only the message, without the stacktrace
|
March 25, 2014 Re: Exception "error" message without stacktrace | ||||
---|---|---|---|---|
| ||||
Posted in reply to Spacen Jasset | Spacen Jasset:
> I caught a FileException, and want to print out the descriptive error, but not the stacktrace. I cannot see how to do this at the moment. I only see the toString function.
void main() {
import std.stdio;
try {
File("hello");
} catch (Exception e) {
writeln(e.msg);
}
}
Bye,
bearophile
|
March 25, 2014 Re: Exception "error" message without stacktrace | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | I see thanks. I couldn't see the throwable class at the time. |
Copyright © 1999-2021 by the D Language Foundation