Are there standard exceptions?

I used throw new Exception("...")in my code since I could not find anything else. I am looking for things like C ++ out_of_range and logic_errorclasses.

std.exception defines several functions that help to handle exceptions, but do not have real types.

Should we define all our own exceptions, or is it Exceptionjust used for everything?

+5
source share
2 answers

For the most part in Phobos, each module has its own type of exception, named after the module - for example. UTFExceptionfor std.utf and FileExceptionfor std.file. There are several that do not have (for example, std.concurrency has several types of exceptions - MessageMismatch, OwnerTerminatedetc.), but this is a general trend. Thus, there are no types of exceptions created with the idea that programmers will create them themselves. There is nothing stopping you from using any of the existing types of exceptions, but in most cases reusing them does not make sense, since they are specific to the module, and not to the specific case.

++ out_of_range logic_error Error, Exception - core.exception.RangeError core.exception.AssertError. Error . core.exception ( OutOfMemoryError). , , . AssertError - , assert, .

, , Throwable . Error Exception Throwable. , Exception, , , , . Error, core.exception, , . , , , Error , - assert.

, , Exception, , , , . Exception, . Exception, , . , Exception , Exception - .

enforce enforceEx, (, , , ).

+7

druntime . errno .. .

0

All Articles