[Kmymoney-devel] Exceptions in MyMoneyFile

Cristian OneČ› onet.cristian at gmail.com
Thu Feb 26 05:40:43 UTC 2015


2015-02-20 18:14 GMT+02:00 victor <pedretti_86 at hotmail.com>:
> Hi,
>
> I have been analyzing the code of mymoneyfile.cpp and I was wondering how
> some of the exceptions handlers could be accessed.
>
> The first one is the exception handler in "QString
> MyMoneyFile::storageId(void)". "testStorageId" in mymoneyfiletest.cpp is
> devoted to this method, but the exception is not thrown in it.

Well, if for example, the storage would not be properly initialized
[1] then a MyMoneyException would be thrown.

>
> The second one is in "const MyMoneyAccount
> MyMoneyFile::openingBalanceAccount(const MyMoneySecurity& s). The first
> "catch" is accessed twice in "testOpeningBalance", but the second nested
> catch is not. I cannot think of a situation that allows me to access this
> handler (in bold):
>
>   try {
>     return openingBalanceAccount_internal(security);
>   } catch (MyMoneyException *e) {
>     delete e;
>     MyMoneyFileTransaction ft;
>     MyMoneyAccount acc;
>
>     try {
>       acc = createOpeningBalanceAccount(security);
>       ft.commit();
>
>     } catch (MyMoneyException* e) {
>       qDebug("Unable to create opening balance account for security %s",
> qPrintable(security.id()));
>       delete e;
>     }
>     return acc;
>   }
>
> Does anybody know which those try-catch blocks were implemented?

As I've said above each MyMoneyFile operation could throw an exception
(for example if the storage is detached) so the code is written to
handle that. Btw: which version of KMyMoney sources are you using? I'm
asking because catch by value [2] is used for a while now.

In conclusion, you are right that there is no way for the catch
handlers to be executed normally, but if someone changes the code in
the wrong way (messes with storage initialization) those handlers
could be hit.

Regards,
Cristian

[1] https://projects.kde.org/projects/extragear/office/kmymoney/repository/revisions/master/entry/kmymoney/mymoney/mymoneyfiletest.cpp#L87
[2] https://projects.kde.org/projects/extragear/office/kmymoney/repository/revisions/master/entry/kmymoney/mymoney/mymoneyfile.cpp#L1066

>
> Thanks in advance.
>
> _______________________________________________
> KMyMoney-devel mailing list
> KMyMoney-devel at kde.org
> https://mail.kde.org/mailman/listinfo/kmymoney-devel
>


More information about the KMyMoney-devel mailing list