shogun-toolbox / shogun

Shōgun
http://shogun-toolbox.org
BSD 3-Clause "New" or "Revised" License
3.03k stars 1.04k forks source link

Use custom exception types #4478

Open vinx13 opened 5 years ago

vinx13 commented 5 years ago

Currently, we use three macros in ASSERT, REQUIRE and SG_ERROR. ASSERT and REQUIRE are assertions. SG_ERROR is used to throw an exception with some message. All of them throw ShogunException.

Throwing custom exceptions instead of ShogunException can provide more information. We can get the information not only from the error message but also from the exception type. The macros REQUIRE_E or SG_THROW added last year allows us to throw exceptions with custom types. We should replace ASSERT, SG_ERROR, REQUIRE with REQUIRE_E or SG_THROW to throw custom exceptions. See Pipeline for example usage of these macros.

This is related to GSoC usability project.

GiannisProkopiou commented 4 years ago

I would really like to take this up since i am very intrested in the usability project.Is there any other informacion or specific steps?

vigsterkr commented 4 years ago

the only additional information regarding this that since this issue was created those macros has been changed to function calls; see for example REQUIRE is require. for more details about this changes check the SGIO.h

other than that as it is described the problem is that we are using one specific exception type to throw mark errors, and these should be actually distinguished a bit better by introducing different exception types. Before really jumping into coding it would be good to come up at least with 2-3 exception types - by looking at the places where we actually call error/require, and see if we should have a common type for certain type of errors.

for example there are times we when we a model's train_machine method is being called and we check that the passed feature class is from a certain type of feature. if that's not the case we should have something similar to an std::invalid_argument exception... but maybe more specific, like InvalidFeatureTypeException.

note before you really jump into coding, provide here the above mentioned 2-3 use-cases and then we can take it from there.