Hi,
In c# i'm used to the following:
Can anyone give an example of something similar in C++.Code:public class Foo{ public void Fun(CustomExceptionHandler customHandler){ try{ // ... } catch(DerivedExceptionType1 ex){ /* Custom handle the exception... */ } catch(DerivedExceptionType2 ex){ /* Custom handle the exception... */ } catch(DerivedExceptionType3 ex){ /* Custom handle the exception... */ } } public delegate void CustomExceptionHandler(Exception ex); } public void Fun(){ Foo foo = new Foo(); foo.Fun( ex => ClientExceptionHandler(ex) ); } public void ClientExceptionHandler(Exception ex){ if(ex.GetType() == typeof(DerivedExceptionType1){ // ... } else if(ex.GetType() == typeof(DerivedExceptionType2){ // ... } else{ // ... }
Using boost is fine, and it certainly doesn't have to be about handling exceptions.
Just something that shows how function pointers relate to lambdas?



LinkBack URL
About LinkBacks


